-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
69 lines (62 loc) · 2.13 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
/*!
* Builded by Impleplus application builder (https://builder.impleplus.com)
* Version 2.0.0
* Link https://www.impleplus.com
* Copyright impleplus.com
* Licensed under MIT (https://mit-license.org)
*/
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var expressLayouts = require('express-ejs-layouts');
var compression = require('compression');
var fileUpload = require('express-fileupload');
var flash = require('connect-flash');
var fs = require('fs');
var { handleError } = require('./app/helper/error');
var common = require('./app/lib/common');
var config = common.getConfig();
global.__config = config;
var impleplusHelper = require('./app/helper/impleplus-helper');
const sequelize = require('./app/helper/db-connect');
if(config.databaseSync=="force"){
sequelize.sync({ force : true }).then(() => {
impleplusHelper.initial();
impleplusHelper.sync();
common.updateConfig({...config,...{databaseSync:""}});
});
}
else if(config.databaseSync=="sync"){
sequelize.sync({ alter : true }).then(() => {
impleplusHelper.sync();
common.updateConfig({...config,...{databaseSync:""}});
});
}
const configNavs = JSON.parse(fs.readFileSync("app/config/nav.json",{ encoding: 'utf8' }));
global.__basedir = __dirname;
global.__configNavs = configNavs;
var app = express();
app.use(compression());
app.use(fileUpload({useTempFiles: true,tempFileDir: '/tmp/'}));
app.set('views', './app/views');
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.use(expressLayouts);
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, '/app/public')));
var passport = require('./app/config/passport/local');
app.use(passport.initialize());
app.use(flash());
app.all('*', impleplusHelper.cookieHandler, async function (req, res, next) {
next();
});
require('./app/routes/impleplus')(app, passport);
app.use(function(err, req, res, next) {
handleError(err, req, res);
});
const port = 3000;
app.listen(port, function () {
console.log(`App running at Port: ${port}`);
})