clean up, prevent broken session sockets

This commit is contained in:
Evert Prants 2019-10-25 15:41:54 +03:00
parent 295a9cfd1b
commit dbffa4262a
Signed by: evert
GPG Key ID: 1688DA83D222D0B5

11
app.js
View File

@ -57,21 +57,11 @@ config = Object.assign({
}, config)
// Constants
const oauthAuth = '{server}/oauth2/authorize?response_type=code&state={state}&redirect_uri={redirect}&client_id={client}&scope=image'
const port = parseInt(config['Streaming']['port'])
const streamServer = config['Streaming']['streamServer']
const streamServerHost = config['Streaming']['serverHost']
const streamAppName = streamServer.match(/\/([\w-_]+)\/$/)[1]
function teval (str, obj) {
let res = str + ''
for (let key in obj) {
if (res.indexOf('{' + key + '}') === -1) continue
res = res.replace('{' + key + '}', obj[key])
}
return res
}
// Database
const dbPromise = Promise.resolve()
.then(() => sqlite.open(path.join(process.cwd(), config['Streaming']['database']), { Promise, cache: true }))
@ -486,6 +476,7 @@ wss.on('connection', (ws, request, client) => {
// Handle upgrade, parse included session
server.on('upgrade', (request, socket, head) => {
sessionParser(request, {}, () => {
if (!request.session || !request.session.id) return socket.destroy()
if (request.session && request.session.passport) {
request.user = request.session.passport.user
}