반응형
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var bodyParser = require('body-parser');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var uploadRouter = require('./routes/upload');
var orderRouter = require('./routes/order');
const partnerRouter = require('./routes/partner');
const partnerOrderRouter = require('./routes/partner_order');
const db = require('./dbconn');
var app = express();
const fs = require('fs');
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/upload', express.static('uploads'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// app.use('/', indexRouter);
// app.use('/users', usersRouter);
// app.use('/upload', uploadRouter);
// app.use('/order', orderRouter);
// app.use('/partner', partnerRouter);
// app.use('/partner_order', partnerOrderRouter);
const dir = path.join(__dirname, 'routes');
fs.readdirSync(dir)
.forEach(file => {
var name = file.substr(0, file.indexOf('.'));
require('./routes/' + name)(app);
});
// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
app.db = db;
module.exports = app;
반응형
'엉터리 개발 이야기 > 개인프로젝트' 카테고리의 다른 글
참고 코드 - views (0) | 2018.11.28 |
---|---|
참고코드 - routes (0) | 2018.11.28 |
참고 코드 - 모델 (0) | 2018.11.28 |
VS Code Node 디버깅 (0) | 2018.11.27 |
소스 예제 (0) | 2018.11.26 |