forked from ajbraus/mean-auth-html
-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
49 lines (37 loc) · 1.13 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
/*
* SERVER.JS
*/
require('dotenv').load();
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var config = require('./config')
, express = require('express')
, app = express()
, resources = require('./resources')
, path = require('path')
, bodyParser = require('body-parser')
, flash = require('connect-flash')
, cors = require('cors')
, logger = require('morgan')
, server = app.listen(config.port)
, mongoose = require('mongoose')
mongoose.connect(config.db);
app.use("/", express.static(path.join(__dirname, 'public')));
app.set('views', path.join(__dirname, 'views'));
app.use(cors());
app.use(logger('dev'));
app.use(flash());
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
var ejs = require('ejs');
app.engine('html', ejs.renderFile);
app.set('view engine', 'html');
// RESOURCES
app.get('/', resources.index);
app.get('/templates/:name', resources.templates);
require('./resources/users')(app);
// redirect all others to the index (HTML5 history)
app.get('*', resources.index);
module.exports = server;
console.log('server running at http://localhost:' + config.port);