-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
83 lines (67 loc) · 2.26 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
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
const express = require('express');
const consolidate = require('consolidate');
const mustache_ex = require('mustache-express');
const path = require('path');
require('dotenv').config();
const app = express();
const mongoose = require('mongoose');
const connectOptions = {
useNewUrlParser: true,
useUnifiedTopology: true,
};
const morgan = require('morgan');
const body_parser = require('body-parser');
const busboy_body_parser = require('busboy-body-parser');
//const expressSwaggerGenerator = require('express-swagger-generator');
//const expressSwagger = expressSwaggerGenerator(app);
const mstRouter = require('./routes/route_mst');
const { mustache } = require('consolidate');
/*const options = {
swaggerDefinition: {
info: {
description: 'Description',
title: 'Title',
version: '1.0.0',
},
host: 'localhost:3000',
produces: ["application/json"],
},
basedir: __dirname,
files: ['./routes//*.js', './models//*.js'],
};*/
//expressSwagger(options);
app.use(body_parser.urlencoded({ extended: true }))
app.use(body_parser.json());
app.use(busboy_body_parser());
app.use((err, req, res, next) => {
if (err instanceof SyntaxError && err.status === 400 && 'body' in err) {
res.status(400).send({ mess: "Bad request" });
return;
}
next();
});
const viewsDir = path.join(__dirname, 'views');
app.engine("mst", mustache_ex(path.join(viewsDir, "partials")));
app.set('views', viewsDir);
app.set('view engine', 'mst');
// usage
app.get('/', function(req, res) {
res.render('index', { index_current: 'current', home_link: 'disabled_link' });
});
app.get('/about', function(req, res) {
res.render('about', { about_current: 'current', about_link: 'disabled_link' });
});
app.use('', mstRouter);
app.use(express.static("./public"));
app.use(express.static("./data"));
app.use(morgan('dev'));
app.listen(process.env.PORT || 3000, async() => {
try {
console.log(`Server ready`);
const client = await mongoose.connect(process.env.DB_CONNECTION_STRING || process.env.DB_CONNECTION_STRING_Test, connectOptions);
console.log('Mongo database connected');
} catch (err) {
console.log(err);
console.log('Mongo database NOT connected');
}
});