mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 08:13:31 +02:00
Rename "roles" to "units". Put units in their own folders.
This commit is contained in:
22
lib/units/websocket/middleware/auth.js
Normal file
22
lib/units/websocket/middleware/auth.js
Normal file
@@ -0,0 +1,22 @@
|
||||
var dbapi = require('../../../db/api')
|
||||
|
||||
module.exports = function(socket, next) {
|
||||
var req = socket.request
|
||||
, token = req.session.jwt
|
||||
if (token) {
|
||||
return dbapi.loadUser(token.email)
|
||||
.then(function(user) {
|
||||
if (user) {
|
||||
req.user = user
|
||||
next()
|
||||
}
|
||||
else {
|
||||
next(new Error('Invalid user'))
|
||||
}
|
||||
})
|
||||
.catch(next)
|
||||
}
|
||||
else {
|
||||
next(new Error('Missing authorization token'))
|
||||
}
|
||||
}
|
||||
10
lib/units/websocket/middleware/cookie-session.js
Normal file
10
lib/units/websocket/middleware/cookie-session.js
Normal file
@@ -0,0 +1,10 @@
|
||||
var cookieSession = require('cookie-session')
|
||||
|
||||
module.exports = function(options) {
|
||||
var session = cookieSession(options)
|
||||
return function(socket, next) {
|
||||
var req = socket.request
|
||||
, res = Object.create(null)
|
||||
session(req, res, next)
|
||||
}
|
||||
}
|
||||
9
lib/units/websocket/middleware/remote-ip.js
Normal file
9
lib/units/websocket/middleware/remote-ip.js
Normal file
@@ -0,0 +1,9 @@
|
||||
var proxyaddr = require('proxy-addr')
|
||||
|
||||
module.exports = function(options) {
|
||||
return function(socket, next) {
|
||||
var req = socket.request
|
||||
req.ip = proxyaddr(req, options.trust)
|
||||
next()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user