-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
51 lines (40 loc) · 1.26 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
// Import express
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
// Setup server port
const { database, port, environment } = require('./config/index');
// Initialize the app
let app = express();
// Configure bodyparser to handle post requests
// for parsing application/xwwww-form-urlencoded
app.use(bodyParser.urlencoded({
extended: true
}));
// for parsing application/json
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, 'public')));
// api routes
const apiRoutes = require('./api/route/apiRoute');
apiRoutes(app);
// configure template engine
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'app/view'));
// app routes
app.get('/', (req, res) => {
// sur la route '/' on affiche le rendu de la page app/view/index.ejs
res.render('index');
});
app.get('/map', (req, res) => { res.render('map') });
// Connect to postgresql and set connection variable
// Launch app to listen to specified port
app.listen(port, function () {
console.log(
`
Running carthageo app on port ${port} in environment ${environment}.
Database config is: ${database}.
App running there http://localhost:3000/
Api running here http://localhost:3000/api
`
);
});