forked from Q00R/Cairo-Metro-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
46 lines (35 loc) · 1.49 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
const db = require('./connectors/db');
const path = require('path');
const express = require('express');
const axios = require("axios");
const app = express();
const authMiddleware = require('./middleware/auth');
const privateApiRoutes = require('./routes/private/api');
const publicApiRoutes = require('./routes/public/api');
const publicViewRoutes = require('./routes/public/view');
const privateViewRoutes = require('./routes/private/view');
const router = express.Router();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hjs');
app.use(express.static(path.join(__dirname, 'static')));
// Config setup to allow our HTTP server to serve static files from our public directory
app.use(express.static('public'));
// Config setup to parse JSON payloads from HTTP POST request body
app.use(express.json());
app.use(express.urlencoded({extended:true}));
// All public routes can be accessible without authentication
publicViewRoutes(app);
publicApiRoutes(app);// uncomment
// If the request is not for a public view/api, then it must pass
// through our authentication middleware first
app.use(authMiddleware); // uncomment
// The routes/views below can only be accessed if the user is authenticated
privateViewRoutes(app);
privateApiRoutes(app);
// If request doesn't match any of the above routes then render the 404 page
app.use(function(req, res, next) {
return res.status(404).render('404');
});
// Create HTTP Server and Listen for Requests
app.listen(3000);