Created
April 14, 2014 13:40
-
-
Save jcolemorrison/10648983 to your computer and use it in GitHub Desktop.
Building an Angular and Express App Part 1: app.js - J Cole Morrison
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var path = require('path'); | |
var favicon = require('static-favicon'); | |
var logger = require('morgan'); | |
var cookieParser = require('cookie-parser'); | |
var bodyParser = require('body-parser'); | |
var routes = require('./routes/index'); | |
var users = require('./routes/users'); | |
var app = express(); | |
app.use(favicon()); | |
app.use(logger('dev')); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded()); | |
app.use(cookieParser()); | |
/// error handlers | |
/** | |
* Development Settings | |
*/ | |
if (app.get('env') === 'development') { | |
// This will change in production since we'll be using the dist folder | |
// This covers serving up the index page | |
app.use(express.static(path.join(__dirname, '../client/.tmp'))); | |
app.use(express.static(path.join(__dirname, '../client/app'))); | |
// Error Handling | |
app.use(function(err, req, res, next) { | |
res.status(err.status || 500); | |
res.render('error', { | |
message: err.message, | |
error: err | |
}); | |
}); | |
} | |
/** | |
* Production Settings | |
*/ | |
if (app.get('env') === 'production') { | |
// changes it to use the optimized version for production | |
app.use(express.static(path.join(__dirname, '/dist'))); | |
// production error handler | |
// no stacktraces leaked to user | |
app.use(function(err, req, res, next) { | |
res.status(err.status || 500); | |
res.render('error', { | |
message: err.message, | |
error: {} | |
}); | |
}); | |
} | |
module.exports = app; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment