-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (38 loc) · 1.38 KB
/
index.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
// load environment configurations
require('./api/config/config');
//Main starting point of the application
const express = require('express');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const app = express();
// import routes
const auth_routes = require('./api/routes/authentication');
const products_routes = require('./api/routes/products');
const sales_routes = require('./api/routes/sales');
const dashboard_routes = require('./api/routes/dashboard');
const employees_routes = require('./api/routes/employees');
// import custom instance of mongoose
const { mongoose } = require('./api/db/mongoose');
const cors = require('cors');
const path = require('path');
const http = require('http');
// Express Setup
// morgan logs all incoming requests
app.use(morgan('combined'));
// Cross-Origin Resource Sharing
app.use(cors());
// parses incoming requests into JSON, '*/*' accepts any type of request
app.use(bodyParser.json({ type: '*/*' }));
// attaches all authentication routes to express
auth_routes(app);
products_routes(app);
sales_routes(app);
dashboard_routes(app);
employees_routes(app);
//Server Setup and Initialization
const PORT = process.env.PORT;
// creates an http server that can receive requests and forward them to express
const SERVER = http.createServer(app);
SERVER.listen(PORT, () => {
console.log('Server listening on port:', PORT);
});