-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
48 lines (39 loc) · 1.43 KB
/
app.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Built in Modules
const path = require('path');
const fs = require('fs');
// Third party modules
const express = require('express');
const exphbs = require('express-handlebars');
const helmet = require('helmet');
const responseTime = require('response-time');
const morgan = require('morgan');
const cors = require('cors');
// Custom Modules
const { eachBetween, jsonItUp } = require('./utilities/hbsHelpers');
// Bring in routes
const index = require('./routes/index');
const launches = require('./routes/launches');
const countries = require('./routes/countries');
const launchProviders = require('./routes/launchProvider');
// Initialize our express application
const app = express();
// Middleware
app.use(cors());
app.use(helmet());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'public')));
// Adds a response time header
app.use(responseTime());
// Setup simple logging of routes using Morgan
const accessLogStream = fs.createWriteStream(path.join(__dirname, 'acccess.log'), { flags: 'a' });
app.use(morgan('combined', { stream: accessLogStream }));
// Templating engine setup
app.engine('handlebars', exphbs({ helpers: { eachBetween, jsonItUp }, defaultLayout: 'main' }));
app.set('view engine', 'handlebars');
// Routes
app.use('/', index);
app.use('/launches', launches);
app.use('/countries', countries);
app.use('/launch-providers', launchProviders);
module.exports = app;