clean up, prevent broken session sockets
This commit is contained in:
parent
295a9cfd1b
commit
dbffa4262a
11
app.js
11
app.js
@ -57,21 +57,11 @@ config = Object.assign({
|
|||||||
}, config)
|
}, config)
|
||||||
|
|
||||||
// Constants
|
// 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 port = parseInt(config['Streaming']['port'])
|
||||||
const streamServer = config['Streaming']['streamServer']
|
const streamServer = config['Streaming']['streamServer']
|
||||||
const streamServerHost = config['Streaming']['serverHost']
|
const streamServerHost = config['Streaming']['serverHost']
|
||||||
const streamAppName = streamServer.match(/\/([\w-_]+)\/$/)[1]
|
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
|
// Database
|
||||||
const dbPromise = Promise.resolve()
|
const dbPromise = Promise.resolve()
|
||||||
.then(() => sqlite.open(path.join(process.cwd(), config['Streaming']['database']), { Promise, cache: true }))
|
.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
|
// Handle upgrade, parse included session
|
||||||
server.on('upgrade', (request, socket, head) => {
|
server.on('upgrade', (request, socket, head) => {
|
||||||
sessionParser(request, {}, () => {
|
sessionParser(request, {}, () => {
|
||||||
|
if (!request.session || !request.session.id) return socket.destroy()
|
||||||
if (request.session && request.session.passport) {
|
if (request.session && request.session.passport) {
|
||||||
request.user = request.session.passport.user
|
request.user = request.session.passport.user
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user