repl.it
Nodejs

No description

fork
loading
Files
  • index.js
  • public
  • views
  • package-lock.json
  • package.json
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
const express = require('express');
const session = require('express-session');
// const sseExpress = require('sse-express');
const bodyParser = require('body-parser');

require('dotenv').config();

const app = express();

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

app.set('view engine', 'ejs');
app.use(express.static('public'));

app.use(session({
	secret: process.env.SESSION_SECRET || 'secret',
	name: 'session-id',
	resave: true,
	saveUninitialized: true,
	cookie: {
		httpOnly: true,
		secure: false
	}
}));

app.get('/', (req, res) => {
	res.render('home');
});

let cons = {}

app.post('/location', (req, res) => {
	req.session.reload(() => {
		cons[req.sessionID] = {x: Number(req.body.x), y: Number(req.body.y), m: req.body.m, c: req.body.c};
	})
	res.json({all: cons, you: req.sessionID});
});

app.listen(process.env.PORT);
node v10.16.0