Move all business logic code under template folder
[oam.git] / code / container-analysis / viewer / app.js
1 /*
2  * Copyright 2023 highstreet technologies and others
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
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');
22
23 const indexRouter = require('./routes/index');
24
25 const app = express();
26
27 // view engine setup
28 app.set('views', path.join(__dirname, 'views'));
29 app.set('view engine', 'pug');
30
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')));
36
37 app.use('/', indexRouter);
38
39 // catch 404 and forward to error handler
40 app.use(function(req, res, next) {
41   next(createError(404));
42 });
43
44 // error handler
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 : {};
49
50   // render the error page
51   res.status(err.status || 500);
52   res.render('error');
53 });
54
55 module.exports = app;