2 * Copyright 2023 highstreet technologies and others
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 const createError = require('http-errors');
18 const express = require('express');
19 const path = require('path');
20 const cookieParser = require('cookie-parser');
21 const logger = require('morgan');
23 const indexRouter = require('./routes/index');
25 const app = express();
28 app.set('views', path.join(__dirname, 'views'));
29 app.set('view engine', 'pug');
31 app.use(logger('dev'));
32 app.use(express.json());
33 app.use(express.urlencoded({ extended: false }));
34 app.use(cookieParser());
35 app.use(express.static(path.join(__dirname, 'public')));
37 app.use('/', indexRouter);
39 // catch 404 and forward to error handler
40 app.use(function(req, res, next) {
41 next(createError(404));
45 app.use(function(err, req, res, next) {
46 // set locals, only providing error in development
47 res.locals.message = err.message;
48 res.locals.error = req.app.get('env') === 'development' ? err : {};
50 // render the error page
51 res.status(err.status || 500);