forked from Fortellis-Dev/backend-starter-seed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
56 lines (45 loc) · 1.08 KB
/
app.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
'use strict';
/**
* Load Dependencies
*/
const express = require('express'),
bodyParser = require('body-parser'),
path = require('path');
const DEFAULT_PORT = 3000;
/**
* Load application routes
*/
const configureAppointmentRoutes = require('./src/appointments/appointments.routes');
/**
* Create Express server
*/
const app = express();
/**
* Adding middleware for Express
*/
/* Request body parser parses request body to json for all incoming requests. */
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
/**
* Configuring static content directory
*/
app.use(express.static(path.join(__dirname, 'public')))
/**
* Configuring application routes
*/
configureAppointmentRoutes(app);
/**
* Adding global eror handler
*/
app.use(function errorHandler(err, req, res, next) {
res.status(500)
res.json({ error: err.toString() });
});
/**
* Start express server
*/
app.listen(process.env.PORT || DEFAULT_PORT, function () {
console.log('awesome appointments app running on port 3000, go to http://localhost:3000')
});