WIP
This commit is contained in:
parent
03edd9c7e0
commit
6422c36644
6 changed files with 71 additions and 10 deletions
16
lib/app.js
16
lib/app.js
|
|
@ -9,6 +9,8 @@ var plugins = require('./plugins')
|
|||
var logger = require('./logger')
|
||||
var configManager = require('./config-manager')
|
||||
|
||||
const db = require('./db')
|
||||
|
||||
module.exports = function (options) {
|
||||
var app = express()
|
||||
var server
|
||||
|
|
@ -61,10 +63,14 @@ module.exports = function (options) {
|
|||
server = http.createServer(app)
|
||||
|
||||
authMiddleware = function (req, res, next) {
|
||||
req.device = {}
|
||||
console.log('DEBUG2')
|
||||
console.log(req.route)
|
||||
return next()
|
||||
const deviceId = req.connection.getPeerCertificate().fingerprint
|
||||
const sql = 'select id from devices where device_id=$1 and authorized=$2'
|
||||
db.one(sql, [deviceId, true])
|
||||
.then(() => {
|
||||
req.deviceId = deviceId
|
||||
next()
|
||||
})
|
||||
.catch(e => res.status(403).end())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -72,7 +78,7 @@ module.exports = function (options) {
|
|||
|
||||
var localApp = express()
|
||||
localApp.use(bodyParser.json())
|
||||
var localServer = http.createServer(localApp)
|
||||
var localServer = http.createServer({localAddress: 'localhost'}, localApp)
|
||||
var localPort = 7070
|
||||
|
||||
console.log('DEBUG7 ****************')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue