Rewrite phase 1.
Started improved client code structure. Implemented session based authentication serverside. Implemented user, match, and sport database models serverside. Implemented Controllers for variety of C and R operations of CRUD.
This commit is contained in:
47
sports-matcher/server/server.js
Normal file
47
sports-matcher/server/server.js
Normal file
@@ -0,0 +1,47 @@
|
||||
import express from "express";
|
||||
import bodyParser from "body-parser";
|
||||
import mongoose from "mongoose";
|
||||
import UserController from "./controllers/userController.js";
|
||||
import MatchController from "./controllers/matchController.js";
|
||||
import SportController from "./controllers/sportController.js";
|
||||
import { userSession } from "./middleware/authority.js";
|
||||
import { mongooseDbName, mongoURI } from "./database/mongoose.js";
|
||||
import cors from "cors";
|
||||
|
||||
const server = express();
|
||||
const port = process.env.PORT || 5000;
|
||||
|
||||
server.use(express.static("public")); // For all client files.
|
||||
|
||||
// Connection documentation: https://mongoosejs.com/docs/connections.html
|
||||
try {
|
||||
mongoose.connect(mongoURI, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
dbName: mongooseDbName,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
mongoose.set("bufferCommands", false); // We want to know if there are connection issues immediately for development. Disables globally.
|
||||
|
||||
server.use(cors());
|
||||
}
|
||||
|
||||
// Docs: https://www.npmjs.com/package/body-parser
|
||||
server.use(bodyParser.json());
|
||||
server.use(bodyParser.urlencoded({ extended: true }));
|
||||
|
||||
server.use(userSession);
|
||||
|
||||
server.use("/user", UserController);
|
||||
server.use("/match", MatchController);
|
||||
server.use("/sport", SportController);
|
||||
|
||||
|
||||
server.listen(port, () => {
|
||||
console.log(`Server listening on port ${port}.`);
|
||||
});
|
||||
Reference in New Issue
Block a user