-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
44 lines (33 loc) · 1.08 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
var http = require('http');
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var logger = require('morgan');
//Optional - enables getting form data and attach it to the body
//urlencoded is now part of middleware
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
//logger init
app.use(logger('dev'));
//set the public resources to be downloaded from server
app.use(express.static(__dirname + "/public"));
var ejsEngine = require("ejs-locals");
app.engine("ejs", ejsEngine); //support master pages
app.set("view engine", "ejs"); //ejs view engine
//map routes
var controlelrs = require("./controllers"); //automatically insantiate index.js
controlelrs.init(app);
module.exports = app;
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
res.render('error', {
message: 'error',
title: 'error',
error: err
});
});
var port=process.env.PORT || 3000;
console.log("listening at port "+port);
app.listen (port);