1 /*******************************************************************************
2 * Copyright (c) 2017 Kumar Rishabh and others.
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 *******************************************************************************/
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');
17 var routes = require('./routes/index');
18 var search_projects = require('./routes/search_projects');
23 app.set('views', path.join(__dirname, 'views'));
24 app.set('view engine', 'jade');
27 var db = require('mysql2');
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')));
37 // Make our db accessible to our router
38 app.use(function(req,res,next){
44 app.use('/search_projects', search_projects);
47 // Some Error handling for now #TODO Remove
49 /// catch 404 and forwarding to error handler
50 app.use(function(req, res, next) {
51 var err = new Error('Not Found');
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);
69 // production error handler
70 // no stacktraces leaked to user
71 app.use(function(err, req, res, next) {
72 res.status(err.status || 500);