-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
58 lines (50 loc) · 1.32 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
55
56
57
58
// Requirement imports
const mongoose = require('mongoose');
const cookieSession = require('cookie-session');
const express = require('express');
const path = require('path');
const routes = require('./routes');
const { getProjects } = require('./src/controller/projectController');
// mongoose connection
mongoose.Promise = global.Promise;
mongoose.connect('mongodb://localhost:27017/UMLHero', {
useNewUrlParser: true,
useUnifiedTopology: true,
});
// setup for server listening port
const port = 3000;
const app = express();
app.use(
cookieSession({
name: 'sesssion',
keys: ['Gajisdfoookll', 'ahsdfomviiiiiAA'],
})
);
app.listen(port, () => {
console.log(`Express Server listening on port: ${port}!`);
});
// View Engine setup
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, './views'));
app.use(express.static(path.join(__dirname, './static')));
// middleware functions and variables for global site template usage
app.locals.siteName = 'UML Hero';
app.use(async (request, response, next) => {
try {
return next();
} catch (err) {
return next(err);
}
});
app.use(express.json());
app.use(
express.urlencoded({
extended: true,
})
);
// Routes implementation. Helps route requests to other routes
app.use(
'/',
// add additional services here
routes('./views/projects')
);