-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (37 loc) · 1.09 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
const express = require('express');
const app = express();
const dotenv = require('dotenv');
dotenv.config();
const path = require('path');
const cors = require('cors')
const logger = require('./logger');
const requestIp = require('request-ip');
app.use(express.json());
app.use(cors());
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname + '/public')));
// Server Logs
app.use((req, res, next) => {
const ipAddress = requestIp.getClientIp(req);
const requestPath = req.path;
const method = req.method;
logger.info(`Request received`, { ip: ipAddress, path: requestPath, method: method });
next();
});
// Port Setting
const PORT = process.env.PORT;
// DataBase
const db = require('./models');
//Server Test
app.get('/', (req, res) => {
res.send(`AFILL Server is Running Port ${process.env.PORT}`);
});
// API Router Call
const ApiRouter = require('./routes/');
app.use('/', ApiRouter);
// Port
db.sequelize.sync().then(() => {
app.listen(PORT, () => {
logger.info(`AFILL Server Started on Port ${process.env.PORT}`);
});
});