-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
39 lines (32 loc) · 1.02 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require("dotenv").config();
const express = require("express");
const cors = require("cors");
const app = express();
const {connectToDB} = require("./src/db/db");
const errorHandler = require("./src/middlewares/error");
const {ignoreFiles} = require("./src/middlewares/common");
const api = require("./src/controllers/api");
const client = require("./src/controllers/client");
const error = require("./src/controllers/error.js")
const path = require("path");
// configurations
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "ejs");
app.use(express.static(__dirname + "/public"));
// connect to database
connectToDB();
// ignore automatic file requests from browsers
app.use(ignoreFiles)
// main app routes
app.use(client);
app.use(api);
// for error handling
app.use(errorHandler);
// route for err
app.use("/error", error);
app.listen(8000, (req, res) => {
console.log("Huzzah! Successfully running on port 8000!");
});