Merge changes from topics 'deployment_handler_refactor', 'deployment_handler'
[releng.git] / utils / test / vnfcatalogue / VNF_Catalogue / app.js
1 /*******************************************************************************
2  * Copyright (c) 2017 Kumar Rishabh and others.
3  *
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Apache License, Version 2.0
6  * which accompanies this distribution, and is available at
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *******************************************************************************/
9
10 var express = require('express');
11 var path = require('path');
12 var favicon = require('serve-favicon');
13 var logger = require('morgan');
14 var cookieParser = require('cookie-parser');
15 var bodyParser = require('body-parser');
16
17 var routes = require('./routes/index');
18 var search_projects = require('./routes/search_projects');
19
20 var app = express();
21
22 // view engine setup
23 app.set('views', path.join(__dirname, 'views'));
24 app.set('view engine', 'jade');
25
26 // Database
27 var db = require('mysql2');
28
29 // uncomment after placing your favicon in /public
30 //app.use(favicon(__dirname + '/public/favicon.ico'));
31 app.use(logger('dev'));
32 app.use(bodyParser.json());
33 app.use(bodyParser.urlencoded({ extended: false }));
34 app.use(cookieParser());
35 app.use(express.static(path.join(__dirname, 'public')));
36
37 // Make our db accessible to our router
38 app.use(function(req,res,next){
39     req.db = db;
40     next();
41 });
42
43 app.use('/', routes);
44 app.use('/search_projects', search_projects);
45
46
47 // Some Error handling for now #TODO Remove
48
49 /// catch 404 and forwarding to error handler
50 app.use(function(req, res, next) {
51     var err = new Error('Not Found');
52     err.status = 404;
53     next(err);
54 });
55
56
57 // development error handler
58 // will print stacktrace
59 if (app.get('env') === 'development') {
60     app.use(function(err, req, res, next) {
61         res.status(err.status || 500);
62         res.render('error', {
63             message: err.message,
64             error: err
65         });
66     });
67 }
68
69 // production error handler
70 // no stacktraces leaked to user
71 app.use(function(err, req, res, next) {
72     res.status(err.status || 500);
73     res.render('error', {
74         message: err.message,
75         error: {}
76     });
77 });
78
79 module.exports = app;