This repository has been archived by the owner on Sep 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Hasvi-Backend.js
74 lines (65 loc) · 1.86 KB
/
Hasvi-Backend.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//Required libraries
var express = require('express');
var path = require('path');
var logger = require('morgan');
var bodyParser = require('body-parser');
var engine = require('express-dot-engine');
var versionDebug = require('./util/VersionDebug');
//The URL route events
var routes = require('./routes/index');
//create an express-based app
var app = express();
//view engine setup - using the "dot" engine
app.engine('dot', engine.__express);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'dot');
//Other node.js setup stuff
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'public')));
//Declare the URL routes and map to events
app.use('/', routes);
app.use('/insertData', routes);
app.use('/views/:username/:id', routes);
// error handlers
// development error handler
// will print stacktrace
if (!versionDebug.iot_onAWS()) {
function errorHandler(err, req, res, next) {
if (res.headersSent) {
return next(err);
}
res.status(500);
res.render('error', {
message: err,
error: {},
version: versionDebug.iot_getVersion()
});
}
}
else {
// production error handler
// no stacktraces leaked to user
function errorHandler(err, req, res, next) {
if (res.headersSent) {
return next(err);
}
res.status(500);
res.render('error', {
message: {},
error: {},
version: versionDebug.iot_getVersion()
});
}
}
// catch 404 and forward to error handler
//app.use(function (req, res, next) {
// res.header('Status' , "404");
// res.status(404);
//});
app.use("*", function (req, res) {
res.status(404).send('404');
});
//Export functions in this file
module.exports = app;