-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
79 lines (62 loc) · 1.79 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
/**
* Module dependencies.
*/
const express = require('express');
const dotenv = require('dotenv');
const ejs = require('ejs')
const cors = require('cors');
const path = require('path');
const logger = require('morgan');
const chalk = require('chalk');
const mongoose = require('mongoose')
const http = require('http')
/**
* .env config
*/
dotenv.config({
path: '.env'
});
/**
* Create Express server.
*/
const app = express();
app.use(cors())
/**
* Connect to MongoDB.
*/
require('./configs/mongoose')
/**
* Express configuration.
*/
app.set('port', process.env.PORT || process.env.OPENSHIFT_NODEJS_PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('layouts', path.join(__dirname, 'views/layouts'));
app.set('/uploads', express.static(path.join(__dirname, 'uploads')));
app.set('view engine', 'ejs');
app.use('/public', express.static(path.join(__dirname, 'public')));
app.use('/bootstrap', express.static(path.join(__dirname, '/node_modules/bootstrap/dist')));
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({
extended: true
}));
const router = require('./routers/router.js')
app.use('/', router);
app.use((err, req, res, next) => {
// console.log(req);
res.status(err.status || 500).json({
msg: err.msg || 'We meet an unexpected error.',
success: false,
status: err.status || 500
});
});
var server = http.createServer(app)
const io = require('./configs/socketio').init(server);
io.on('connection', (socket) => {
console.log('%s A user connected.', chalk.red('✓'));
});
server.listen(app.get('port'), () => {
console.log('%s App is running at http://localhost:3000', chalk.green('✓'));
console.log(chalk.magentaBright(' Press CTRL-C to stop'));
});
require('./services/park_sensors');