-
Notifications
You must be signed in to change notification settings - Fork 10
/
server.js
41 lines (32 loc) · 1.02 KB
/
server.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
'use strict';
// Chat application dependencies
var express = require('express');
var app = express();
var path = require('path');
var bodyParser = require('body-parser');
var flash = require('connect-flash');
// Chat application components
var routes = require('./app/routes');
var session = require('./app/session');
var passport = require('./app/auth');
var ioServer = require('./app/socket')(app);
var logger = require('./app/logger');
// Set the port number
var port = process.env.PORT || 3000;
// View engine setup
app.set('views', path.join(__dirname, 'app/views'));
app.set('view engine', 'ejs');
// Middlewares
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static('public'));
app.use(session);
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
app.use('/', routes);
// Middleware to catch 404 errors
app.use(function(req, res, next) {
res.status(404).sendFile(process.cwd() + '/app/views/404.htm');
});
ioServer.listen(port);