app.js 1.46 KB
Newer Older
CHAERIN KIM's avatar
CHAERIN KIM committed
1
2
3
4
5
6
7
8
const createError = require('http-errors');
const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');

const indexRouter = require('./routes/index');
const usersRouter = require('./routes/users');
CHAERIN KIM's avatar
CHAERIN KIM committed
9
const loginRouter = require('./routes/login');
10
const reserveRouter = require('./routes/reserves');
11
const noticeRouter = require('./routes/notices');
12
const connect = require('./schemas');
CHAERIN KIM's avatar
CHAERIN KIM committed
13
14
15

const app = express();
const port = 3030;
CHAERIN KIM's avatar
CHAERIN KIM committed
16
17

require('dotenv').config();
18
connect();
Kim, Chaerin's avatar
어헛    
Kim, Chaerin committed
19

CHAERIN KIM's avatar
CHAERIN KIM committed
20
21
22

app.listen(port, () => console.log(port));

Kim, Chaerin's avatar
어헛    
Kim, Chaerin committed
23
// view engine setup
24
25
// app.set('views', path.join(__dirname, 'views'));
// app.set('view engine', 'pug');
Kim, Chaerin's avatar
어헛    
Kim, Chaerin committed
26
27
28
29
30
31
32
33
34

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('/', indexRouter);
app.use('/users', usersRouter);
CHAERIN KIM's avatar
CHAERIN KIM committed
35
app.use('/login', loginRouter);
36
app.use('/reserves', reserveRouter);
37
app.use('/notices', noticeRouter);
38

Kim, Chaerin's avatar
어헛    
Kim, Chaerin committed
39
40
41
42
43
44
45
46
47
48
49
50
51
// 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);
CHAERIN KIM's avatar
CHAERIN KIM committed
52
  // res.render('error');
Kim, Chaerin's avatar
어헛    
Kim, Chaerin committed
53
54
55
});

module.exports = app;