-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
70 lines (52 loc) · 1.57 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
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
// Get required packages
var express = require('express'),
mongoose = require('mongoose'),
bodyParser = require('body-parser'),
passport = require('passport'),
exphbs = require('express-handlebars'),
morgan = require('morgan'),
compression = require('compression');
// Connect to MongoDB 1
mongoose.connect('mongodb://localhost:27017/blog');
// Create Express Application
var app = express();
// Use packages in app
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json()); // parse application/json
app.use(bodyParser.json({
type: 'application/vnd.api+json'
})); // parse application/vnd.api+json as json
// Logging for shits and giggles
app.use(morgan('dev'));
// Manage uploads & image resizing
var uploads = require('./server/uploads/upload.controller');
app.use(uploads);
//Use passport for authentication
app.use(passport.initialize());
// Setup cors for cross domain posting
var cors = require('./server/cors');
app.use(cors);
//Use compressio
app.use(compression({
threshold: 1000
}));
// Set directory for views
app.set('views', __dirname + '/views');
// Set location of static elements
app.use(express.static(__dirname + '/public'));
// Set view engine to handlebars
app.engine('handlebars', exphbs({
defaultLayout: 'main',
partialsDir: "views/partials/"
}));
app.set('view engine', 'handlebars');
// Use defined port or 3000
var port = process.env.PORT || 3000;
// Register all our routes with /
// app.use('/', routes);
//Load Routing
var routes = require('./routes/index')(app);
// Start server
app.listen(port);