-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
71 lines (57 loc) · 2.22 KB
/
Copy pathserver.js
File metadata and controls
71 lines (57 loc) · 2.22 KB
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
const express = require('express');
const compression = require('compression');
const chalk = require('chalk');
const morgan = require('morgan');
const cors = require('cors');
const bodyParser = require('body-parser');
const helmet = require('helmet');
const socket = require('socket.io');
const app = express();
const server = require('http').createServer(app)
const io = socket.listen(server);
global.io = io;
// const winston = require('./src/config/winston-stream.config');
const cool = require('cool-ascii-faces');
const OAuthServer = require('express-oauth-server');
const OAuth2Server = require('oauth2-server');
const Request = OAuth2Server.Request;
const Response = OAuth2Server.Response;
require('./src/utilities/create-dir.utils');
require('dotenv').config();
// providing a Connect/Express middleware that can be used to enable CORS with various options.
app.use(cors());
app.use(compression());
// Parse incoming request bodies in a middleware before your handlers, available under the req.body property.
app.use(bodyParser.urlencoded({ extended: false }));
// parse application/json
app.use(bodyParser.json());
// Helmet helps you secure your Express apps by setting various HTTP headers. It’s not a silver bullet, but it can help!
// DOC: https://helmetjs.github.io/
app.use(helmet());
// HTTP request logger middleware
app.use(morgan('dev'));
// app.use(morgan('combined', { stream: winston.stream }));
// default api route
app.get("/", (req, res, next) => {
return res.status(200).json({ message: "Welcome to xDemiC api ", cheers: cool() });
});
const publicDir = require('path').join(__dirname, './public');
// console.log(publicDir);
app.use(express.static(publicDir));
// import all routes at once
require('./src/utilities/routes.utility')(app);
// Handling non-existing routes
// Handling non-existing routes
require('./src/utilities/error-handler.utility')(app);
// db config
require('./src/config/db.config');
const port = process.env.PORT || 5500;
server.listen(port, () => console.log(`%s 🚀 Server is listening on port ${port}`, chalk.green('✓')));
// socket io connection
let interval;
io.on("connection", socket => {
console.log("New client connected");
if (interval) {
clearInterval(interval);
}
});