-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (31 loc) · 1.11 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
const express = require('express')
const http = require('http')
const app = express()
const server = http.Server(app)
const bodyParser = require('body-parser')
const jwt = require('jsonwebtoken')
const jwtSecret = process.env.JWTSECRET || 'fakeSecret' // ./secret.txt
const SillyName = require('./lib/silly')
const sng = new SillyName({textMode: 'TitleCase'})
require('./game/sps')(server)
app.set('port', process.env.PORT || 3001)
// app.get('/', (req, res) => {})
app.use('/', express.static('./public'))
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.post('/login', function (req, res) {
// TODO: validate the actual user user
var profile = {
username: req.body.username || sng.generate(),
first_name: req.body.first_name,
last_name: req.body.last_name,
email: req.body.email
}
// we are sending the profile in the token
var token = jwt.sign(profile, jwtSecret, { expiresIn: 60 * 5 })
res.json({token: token})
})
const listener = server.listen(app.get('port'), (err) => {
if (err) console.error(err)
console.log(`Listening on ${listener.address().port}`)
})