-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
60 lines (44 loc) · 1.27 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
49
50
51
52
53
54
55
56
57
const dotenv = require("dotenv");
dotenv.config();
const moment = require("moment");
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
const axios = require("axios");
const { connect } = require("./connect");
const { cron } = require("./libs/cron");
// Add a request interceptor
axios.interceptors.request.use(function (config) {
// Do something before request is sent
console.log("config", config.url);
return config;
}, function (error) {
// Do something with request error
return Promise.reject(error);
});
var app = express();
if (
process.env.NODE_ENV == "local" ||
process.env.NODE_ENV == "staging" ||
"1" == process.env.ALLOW_CORS
) {
app.use(require("cors")())
}
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use('/api', express.static(path.join(__dirname, 'public')));
var fs = require('fs')
module.exports = async () => {
/**Connect Database */
let con = await connect();
/** Start Cron job */
await cron();
var indexRouter = require('./routes/index');
var apiRouter = require('./routes/api');
app.use('/api', indexRouter);
app.use('/api', apiRouter);
return app;
};