forked from himanshuagarwal190/ChatApp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
34 lines (28 loc) · 830 Bytes
/
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
const express = require('express');
const bodyParser = require('body-parser');
const socket = require('socket.io')
const app = express();
app.use(bodyParser.urlencoded({extended: false}));
app.use(express.static('public'));
app.set('view engine', 'ejs');
var port = process.env.PORT || 3000;
//Render Index page
app.get('/', (req, res) => {
res.render('index')
})
//Get username and roomname from form and pass it to room
app.post('/room', (req, res) => {
roomname = req.body.roomname;
username = req.body.username;
res.redirect(`/room?username=${username}&roomname=${roomname}`)
})
//Rooms
app.get('/room', (req, res)=>{
res.render('room')
})
//Start Server
const server = app.listen(port, () => {
console.log(`Server Running on ${port}`)
})
const io = socket(server);
require('./utils/socket')(io);