-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
72 lines (65 loc) · 2.18 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* eslint-disable no-undef */
require("dotenv").config();
const bodyParse = require("body-parser");
const config = require("./src/config/database/config");
const consign = require("consign");
const cors = require("cors");
const express = require("express");
const knex = require("knex");
const logger = require("knex-logger");
// const path = require('path');
const app = express();
let database = knex(config);
app.db = database;
database = () => ({
log: {
debug(message) {
console.log(message);
},
deprecate(message) {
console.log(message);
},
error(message) {
console.log(message);
},
warn(message) {
console.log(message);
},
}
});
// -- Use a static client builder project
// const pathPublic = path.join(__dirname, '../public');
// app.use(express.static(pathPublic));
app.use(bodyParse.json());
app.use(cors());
if (process.env.APP_DEBUG === true) app.use(logger(database));
consign()
.include("./src/core/passport.js")
.then("./src/helpers/usuario.js")
.then("./src/middleware/knexHook.js")
.then("./src/middleware/authorization.js")
.then("./src/controller/auth.js")
.then("./src/controller/administration/user.js")
.then("./src/controller/administration/screen.js")
.then("./src/controller/administration/request_screen.js")
.then("./src/controller/administration/user_screen.js")
.then("./src/controller/administration/user_request.js")
.then("./src/routes/")
.into(app);
app.get("*", (req, res) => {
// res.sendFile(path.join(pathPublic, 'index.html'))
res.status(401).send({
error: `Invalid access parameter.
Please check the URL or Type of request.
Ex: POST, GET, PUT or DELETE.
http://url/request`
});
});
app.listen(process.env.APP_PORT, process.env.APP_HOST, () => {
// console.log(`
// |======================================================|
// | BY EDER FERRAZ CACIANO |
// |======================================================|
// `)
console.log(`Servidor inicializado! - Host: ${process.env.APP_HOST} - Port: ${process.env.APP_PORT} - Database: ${process.env.DB_DATABASE}`)
});