-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (40 loc) · 1.44 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
const express = require('express');
const app = express();
const cors = require('cors');
const expressValidator = require("express-validator");
const path = require('path');
app.use(express.json());
app.use(cors());
app.use(expressValidator());
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
res.header('Access-Control-Expose-Headers', '*');
next();
});
global.ROOT = __dirname;
global.PROD = process.env.NODE_ENV === 'prod';
app.use(`/src`, express.static(path.resolve(__dirname, 'pages/src')));
app.use(`/media`, express.static(path.resolve(__dirname, 'media')));
const fs = require("fs");
["System", "classes"].forEach(dir => {
try {
const files = fs.readdirSync(dir);
files.forEach(function (file) {
const Class = require(`./${dir}/${file}`);
global[file.split(".")[0]] = Class;
});
} catch (e) {
console.log(e);
}
});
const consign = require('consign');
consign().include('controllers').into(app);
const port = PROD ? 3000 : 3333;
app.listen(port, async () => {
console.log("--------------------------------------------");
for (let index = 0; index < 10; index++) console.log("\n");
console.clear();
console.log(`Rodando na porta ${port}`);
})