-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
41 lines (36 loc) · 1.34 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
require('dotenv').config();
const express = require('express');
const bodyParser = require('body-parser');
const path = __dirname + '/views/';
const app = express();
const server = require('http').createServer(app);
const cors = require('cors');
const { Server } = require('socket.io');
const socketChat = require('./api/controllers/chatController');
const PORT = process.env.PORT || 9000;
const isDeveloping = process.env.IS_DEVELOPING === '1'; // TODO: change .env before pushing to ec2
const originURL = isDeveloping ? 'http://localhost:3000' : 'https://shelpy.co';
const io = new Server(server, {
cors: {
origin: originURL,
methods: ['GET', 'POST'],
},
});
io.on('connection', socketChat);
// Enable if you're behind a reverse proxy (Heroku, Bluemix, AWS ELB, Nginx, etc)
// see https://expressjs.com/en/guide/behind-proxies.html
// app.set('trust proxy', 1); // This enables IP to show so that we can rate limit individual IP rather than on every IP
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use([
require('./api/routes/route'),
express.static(path)
]);
app.use(cors());
app.get("/*", function (req, res) {
res.sendFile(path + "index.html");
});
// app.listen(PORT, () => console.log(`Listening on port ${PORT}`));
server.listen(PORT, () => {
console.log(`Socket server listening to port ${PORT}`);
});