-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
30 lines (22 loc) · 727 Bytes
/
app.js
File metadata and controls
30 lines (22 loc) · 727 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// dependencies
const express = require('express');
const createHttpErrors = require('http-errors');
const path = require('path');
const urlRouter = require('./routes/urlRouter');
const ShortURL = require('./models/urlModel');
const app = express();
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
// view engine
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
// router
app.use('/', urlRouter);
app.use((req, res, next) => {
next(createHttpErrors.NotFound());
});
app.use((err, req, res, next) => {
res.status(err.status || 500).render('index', { error: err.message });
});
module.exports = app;