removed express from app.js
This commit is contained in:
parent
f67529a75e
commit
ffcb50e196
41
app.js
41
app.js
@ -18,46 +18,7 @@ var env = 'production';
|
||||
|
||||
if( process.env.NODE_ENV !== 'production' )
|
||||
{
|
||||
var express = require('express');
|
||||
var app = express();
|
||||
var path = require('path');
|
||||
var bodyParser = require('body-parser');
|
||||
|
||||
// view engine setup
|
||||
app.set('views', path.join(__dirname, 'src/views'));
|
||||
app.set('view engine', 'jade');
|
||||
app.use(bodyParser.json());
|
||||
app.use(bodyParser.urlencoded({ extended: false }));
|
||||
app.use(express.static(path.join(__dirname, 'dist')));
|
||||
|
||||
app.get('/', function(req, res) {
|
||||
res.render('index');
|
||||
});
|
||||
|
||||
// catch 404 and forward to error handler
|
||||
app.use(function(req, res, next) {
|
||||
var err = new Error('Not Found');
|
||||
err.status = 404;
|
||||
next(err);
|
||||
});
|
||||
|
||||
// error handlers
|
||||
app.use(function(err, req, res, next) {
|
||||
res.status(err.status || 500);
|
||||
res.render('error', {
|
||||
message: err.message,
|
||||
error: err
|
||||
});
|
||||
});
|
||||
|
||||
// production error handler
|
||||
app.use(function(err, req, res, next) {
|
||||
res.status(err.status || 500);
|
||||
res.render('error', {
|
||||
message: err.message,
|
||||
error: {}
|
||||
});
|
||||
});
|
||||
var app = require('./lib/express');
|
||||
|
||||
server = require('http').createServer(app);
|
||||
}
|
||||
|
42
lib/express.js
Normal file
42
lib/express.js
Normal file
@ -0,0 +1,42 @@
|
||||
var express = require('express');
|
||||
var app = express();
|
||||
var path = require('path');
|
||||
var bodyParser = require('body-parser');
|
||||
|
||||
// view engine setup
|
||||
app.set('views', path.join(__dirname, '../src/views'));
|
||||
app.set('view engine', 'jade');
|
||||
app.use(bodyParser.json());
|
||||
app.use(bodyParser.urlencoded({ extended: false }));
|
||||
app.use(express.static(path.join(__dirname, '../dist')));
|
||||
|
||||
app.get('/', function(req, res) {
|
||||
res.render('index');
|
||||
});
|
||||
|
||||
// catch 404 and forward to error handler
|
||||
app.use(function(req, res, next) {
|
||||
var err = new Error('Not Found');
|
||||
err.status = 404;
|
||||
next(err);
|
||||
});
|
||||
|
||||
// error handlers
|
||||
app.use(function(err, req, res, next) {
|
||||
res.status(err.status || 500);
|
||||
res.render('error', {
|
||||
message: err.message,
|
||||
error: err
|
||||
});
|
||||
});
|
||||
|
||||
// production error handler
|
||||
app.use(function(err, req, res, next) {
|
||||
res.status(err.status || 500);
|
||||
res.render('error', {
|
||||
message: err.message,
|
||||
error: {}
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = app;
|
Loading…
Reference in New Issue
Block a user