|
| 1 | +var express = require('express'); |
| 2 | +var path = require('path'); |
| 3 | +var favicon = require('serve-favicon'); |
| 4 | +var logger = require('morgan'); |
| 5 | +var cookieParser = require('cookie-parser'); |
| 6 | +var bodyParser = require('body-parser'); |
| 7 | + |
| 8 | +var index = require('./routes/index'); |
| 9 | +var users = require('./routes/users'); |
| 10 | + |
| 11 | +var app = express(); |
| 12 | + |
| 13 | +// view engine setup |
| 14 | +app.set('views', path.join(__dirname, 'views')); |
| 15 | +app.engine('art', require('express-art-template')); |
| 16 | +app.set('view options', { |
| 17 | + debug: process.env.NODE_ENV !== 'production' |
| 18 | +}); |
| 19 | + |
| 20 | +app.set('view engine', 'art'); |
| 21 | + |
| 22 | +// uncomment after placing your favicon in /public |
| 23 | +//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); |
| 24 | +app.use(logger('dev')); |
| 25 | +app.use(bodyParser.json()); |
| 26 | +app.use(bodyParser.urlencoded({ extended: false })); |
| 27 | +app.use(cookieParser()); |
| 28 | + |
| 29 | +app.use("/public",express.static(path.join(__dirname, '/public'))); |
| 30 | + |
| 31 | +app.use('/', index); |
| 32 | +app.use('/users', users); |
| 33 | +// app.use('*', function(req, res, next) { |
| 34 | +// res.header("Access-Control-Allow-Origin", "*"); |
| 35 | +// res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS'); |
| 36 | +// res.header("Access-Control-Allow-Headers", "X-Requested-With"); |
| 37 | +// res.header('Access-Control-Allow-Headers', 'Content-Type'); |
| 38 | +// next(); |
| 39 | +// }); |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | +// catch 404 and forward to error handler |
| 44 | +app.use(function(req, res, next) { |
| 45 | + var err = new Error('Not Found'); |
| 46 | + err.status = 404; |
| 47 | + next(err); |
| 48 | +}); |
| 49 | + |
| 50 | +// error handler |
| 51 | +app.use(function(err, req, res, next) { |
| 52 | + // set locals, only providing error in development |
| 53 | + res.locals.message = err.message; |
| 54 | + res.locals.error = req.app.get('env') === 'development' ? err : {}; |
| 55 | + |
| 56 | + // render the error page |
| 57 | + res.status(err.status || 500); |
| 58 | + res.render('error'); |
| 59 | +}); |
| 60 | + |
| 61 | +module.exports = app; |
0 commit comments