-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
54 lines (43 loc) · 1.1 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Import Statements
const express = require("express");
const http = require("http");
const cors = require("cors");
const bodyParser = require("body-parser");
// const logging = require("./middlewares/logging");
// Creating Express App
const app = express();
// Middlewares
app.use(express.json());
// app.use(logging);
app.use(
cors({
origin: "*",
})
);
// PARSE application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true }));
// PARSE application/json
app.use(bodyParser.json());
// Routes
app.use("/api/form", require("./routes/form"));
// Basic or Home Route
app.get("/", (req, res) => {
// Sending Response
return res.send({
server: "CSS Audition Backend",
status: "Online",
host: req.headers.host,
});
});
// Defining Server Port
const PORT = process.env.PORT || 8000;
// Establishing Database Connection
require("./config/db.js");
// Creating Server
const SERVER = http.createServer(app);
// Listening to Server
app.listen(PORT, () => {
console.log(`Server is up and running at PORT : ${PORT}`);
});
// Exporting Server for index.js
module.exports = SERVER;