init commit
This commit is contained in:
2
server/.gitignore
vendored
Normal file
2
server/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
*.env
|
||||
8
server/bin/www
Normal file
8
server/bin/www
Normal file
@@ -0,0 +1,8 @@
|
||||
// if sockets are required for this project to function,
|
||||
// this file will serve as the point of execution for the server
|
||||
|
||||
module.exports = (app) => {
|
||||
app.listen(port, () => {
|
||||
console.log("Listening on " + port);
|
||||
})
|
||||
}
|
||||
13
server/db/Pool.js
Normal file
13
server/db/Pool.js
Normal file
@@ -0,0 +1,13 @@
|
||||
require('dotenv').config();
|
||||
const { Pool } = require("pg");
|
||||
|
||||
const conString = process.env.CONNECTION;
|
||||
|
||||
const pool = new Pool({
|
||||
connectionString: 'our connection string'
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
pool,
|
||||
connect: () => pool.connect()
|
||||
}
|
||||
0
server/index.js
Normal file
0
server/index.js
Normal file
5
server/loaders/api.js
Normal file
5
server/loaders/api.js
Normal file
@@ -0,0 +1,5 @@
|
||||
const router = require('../routes');
|
||||
|
||||
module.exports = (app) => {
|
||||
|
||||
}
|
||||
17
server/loaders/express.js
Normal file
17
server/loaders/express.js
Normal file
@@ -0,0 +1,17 @@
|
||||
require('dotenv').config();
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const session = require('express-session');
|
||||
|
||||
module.exports = () => {
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
|
||||
app.use(session({
|
||||
// session details
|
||||
}))
|
||||
|
||||
return app;
|
||||
}
|
||||
12
server/loaders/index.js
Normal file
12
server/loaders/index.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const expressLoader = require('./express');
|
||||
const passportLoader = require('./passport');
|
||||
const apiLoader = require('./api');
|
||||
|
||||
// app is passed in from 'index.js' at the server directory level
|
||||
module.exports = async (app) => {
|
||||
const express = await expressLoader(app);
|
||||
const passport = await passportLoader(express);
|
||||
|
||||
// we may include passport here to assist with user auth flows
|
||||
await apiLoader(app, passport);
|
||||
}
|
||||
0
server/loaders/passport.js
Normal file
0
server/loaders/passport.js
Normal file
2110
server/package-lock.json
generated
Normal file
2110
server/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
26
server/package.json
Normal file
26
server/package.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "server",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"socket-start": "nodemon ./bin/www",
|
||||
"start": "nodemon ."
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.0.1",
|
||||
"express": "^4.18.1",
|
||||
"express-session": "^1.17.3",
|
||||
"passport": "^0.6.0",
|
||||
"passport-local": "^1.0.0",
|
||||
"pg": "^8.7.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^2.0.19"
|
||||
}
|
||||
}
|
||||
12
server/routes/drivers.js
Normal file
12
server/routes/drivers.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const router = require('express').Router();
|
||||
|
||||
module.exports = (app) => {
|
||||
app.use('/drivers', router);
|
||||
|
||||
router.get('/:id', (req, res) => {
|
||||
// get the driver with this id from the database
|
||||
const driver = '';
|
||||
if (!driver) throw new Error('no driver');
|
||||
res.status(200).send(driver);
|
||||
});
|
||||
}
|
||||
14
server/routes/index.js
Normal file
14
server/routes/index.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const router = require('express').Router();
|
||||
|
||||
/**
|
||||
* The goal is to gather these bits of code that work on specific parts of the program,
|
||||
* gather them together so they can be streamlined and funneled into the next highest
|
||||
* section of the program.
|
||||
*/
|
||||
|
||||
module.exports = (app) => {
|
||||
app.use(require('./drivers'));
|
||||
app.use(require('./users'));
|
||||
|
||||
return app;
|
||||
}
|
||||
12
server/routes/users.js
Normal file
12
server/routes/users.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const router = require('express').Router();
|
||||
|
||||
module.exports = (app) => {
|
||||
app.use('/users', router);
|
||||
|
||||
router.get('/:id', (req, res) => {
|
||||
// get the user with this id from the database
|
||||
const user = '';
|
||||
if (!user) throw new Error('no user');
|
||||
res.status(200).send(user);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user