-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (36 loc) · 1.13 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
/**
* Copyright © StoredIn, 2020
* Developer: Prashant Shrestha (www.prashant.me)
* Date: Wed 05 Aug 2020 11:45:54 AM EDT
* Document: app.js (Entry)
* Licensed: MIT (Open Source)
*/
const express = require('express');
const app = express();
const fs = require('fs');
const { DEV, DIRECTORY } = require('./config.js');
// Strictly for file & path management.
global.__basedir = __dirname;
// Heroku port specification.
const PORT = process.env.PORT || 80;
// Development mode, use morgan to log requests & requests' type.
if (DEV) {
const morgan = require('morgan');
app.use(morgan('dev'));
}
// Setup the directory.. if it doesn't exist. Blocks the app but worth it for start.
if (!fs.existsSync(`${__basedir}/${DIRECTORY.paste}`)) {
fs.mkdirSync(`${__basedir}/${DIRECTORY.paste}`);
}
// Importing and using express routes.
const singleRouter = require('./routes/route.paste');
// Main page, instructions and such!
app.use('/', singleRouter);
// Start server.
app.listen(PORT, () => {
console.log(
`Listening on Port: *:${PORT}${
DEV && DEV === true ? ' in development mode.' : ''
}`
);
});