-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
105 lines (86 loc) · 1.72 KB
/
index.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"use strict";
/**
* Gather dependencies
*/
const express = require("express");
const fileUpload = require('express-fileupload');
const env = require('dotenv');
const path = require('path');
const cors = require('cors');
const logger = require('morgan');
/**
* Read from dotenv
*/
env.config({
path: process.env.NODE_ENV === "test"
? path.resolve(process.cwd(), '.env.testing')
: path.resolve(process.cwd(), '.env')
})
console.log("Starting in " + process.env.APP_ENV + " mode!");
/**
* Import all routers
*/
const routerProvider = require('./config/routes');
/**
* Enable global helpers
*/
require('./config/global');
/**
* Initialize the database
*/
const db = require("./config/database")();
/**
* Enable cron
*/
const cron = require('./config/cron');
/**
* Initialize the application
*/
const app = express();
/**
* Initiate the port
*/
const port = process.env.PORT || 1000;
/**
* Initialize webpush
*/
// const webpush = require('web-push');
/**
* Initialize Logger
*/
if (process.env.NODE_ENV !== "test") {
app.use(logger('dev'));
}
/**
* Static Path
*/
app.use(express.static(path.join(__dirname, 'public')));
/**
* Use body parser and form and web push
*/
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(fileUpload({
useTempFiles: true,
debug: process.env.APP_ENV === "development"
}));
/**
* Enable cors
*/
app.use(cors());
/**
* Use All Routes
*/
app.use('/', routerProvider);
/**
* default path
*/
app.use("*", (req, res) => {
if (req.headers.accept === "application/json") {
res.status(404).json({ message: "Not found!" });
} else {
res.status(404).send("Not found!");
}
});
app.use(require('./config/errorhandler'));
module.exports = app;