This repository was archived by the owner on Aug 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
85 lines (72 loc) · 1.93 KB
/
app.js
File metadata and controls
85 lines (72 loc) · 1.93 KB
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
75
76
77
78
79
80
81
82
83
84
85
const express = require('express');
const path = require('path');
const favicon = require('serve-favicon');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const expressValidator = require('express-validator');
const expressSession = require('express-session');
// const userVersion = require('./server/helpers/user-version');
const app = express();
const NotFoundError = require('./server/errors/api').NotFoundError;
// db
require('./server/db');
// view engine
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'html');
// app.set('user-version', userVersion);
// base
//app.use(favicon(__dirname + '/dist/favicon.ico'));
app.use(logger('dev'));
app.use(expressValidator({
customValidators: {
isEqual: (value1, value2) => {
return value1 === value2;
}
}
}));
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.use(cookieParser());
// static file
app.use(express.static(path.join(__dirname, 'dist')));
// session
app.use(expressSession({
secret: 'lsj8wu35oiQAF-CUMAV9PGFY8W9-GR-SODHGFJ03W85U4T0Q249U25PQKgas',
resave: false,
saveUninitialized: false
}));
// authentication
require('./server/auth')(app);
// routes
require('./server/routes')(app);
// errors
app.use(function(req, res, next) {
next(new NotFoundError());
});
app.use(function(err, req, res, next) {
// if (req.url.match(/^\/api\//)) {
var obj = {
status: 'error',
type: err.name,
message: err.message,
stack: err.stack
};
if(err.name === 'FieldsValidationError') obj.fields = err.fields;
res.status(err.status || 500).json(obj);
/* } else {
res.render('error', {
message: err.message,
error: err
});
}*/
});
// Catch all other routes and return the index file
/*
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
*/
module.exports = app;