mirror of
https://github.com/zyphlar/doorlock.git
synced 2024-04-03 21:36:03 +00:00
use real timeouts (10s)
This commit is contained in:
parent
bee518e1ef
commit
ad1d060cdc
67
package-lock.json
generated
67
package-lock.json
generated
|
@ -466,6 +466,73 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"connect-timeout": {
|
||||
"version": "1.9.0",
|
||||
"resolved": "https://registry.npmjs.org/connect-timeout/-/connect-timeout-1.9.0.tgz",
|
||||
"integrity": "sha1-vCcyaxIhA3FL6/oNlYurM/ZSLjo=",
|
||||
"requires": {
|
||||
"http-errors": "~1.6.1",
|
||||
"ms": "2.0.0",
|
||||
"on-finished": "~2.3.0",
|
||||
"on-headers": "~1.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"depd": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
|
||||
"integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak="
|
||||
},
|
||||
"ee-first": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
|
||||
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
|
||||
},
|
||||
"http-errors": {
|
||||
"version": "1.6.3",
|
||||
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz",
|
||||
"integrity": "sha1-i1VoC7S+KDoLW/TqLjhYC+HZMg0=",
|
||||
"requires": {
|
||||
"depd": "~1.1.2",
|
||||
"inherits": "2.0.3",
|
||||
"setprototypeof": "1.1.0",
|
||||
"statuses": ">= 1.4.0 < 2"
|
||||
}
|
||||
},
|
||||
"inherits": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
|
||||
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||
},
|
||||
"on-finished": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz",
|
||||
"integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=",
|
||||
"requires": {
|
||||
"ee-first": "1.1.1"
|
||||
}
|
||||
},
|
||||
"on-headers": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.1.tgz",
|
||||
"integrity": "sha1-ko9dD0cNSTQmUepnlLCFfBAGk/c="
|
||||
},
|
||||
"setprototypeof": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz",
|
||||
"integrity": "sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ=="
|
||||
},
|
||||
"statuses": {
|
||||
"version": "1.5.0",
|
||||
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
|
||||
"integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow="
|
||||
}
|
||||
}
|
||||
},
|
||||
"dotenv": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-5.0.1.tgz",
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
"axios": "0.18.0",
|
||||
"body-parser": "1.18.3",
|
||||
"chalk": "2.3.1",
|
||||
"connect-timeout": "^1.9.0",
|
||||
"dotenv": "5.0.1",
|
||||
"easy-usb-relay": "0.0.4",
|
||||
"express": "4.16.3",
|
||||
|
|
|
@ -5,27 +5,40 @@ const moment = require('moment')
|
|||
const path = require('path')
|
||||
const app = express()
|
||||
|
||||
const timeout = require('connect-timeout')
|
||||
function haltOnTimedout (req, res, next) {
|
||||
if (!req.timedout) next()
|
||||
}
|
||||
|
||||
const PORT = process.env.PORT || 3000
|
||||
|
||||
//---------------------------------------------------------
|
||||
// Middleware
|
||||
//---------------------------------------------------------
|
||||
|
||||
// Time out after 10 secs
|
||||
app.use(timeout('10s'))
|
||||
|
||||
// View engine setup
|
||||
app.set('views', path.join(process.cwd(), 'src', 'views'))
|
||||
app.set('view engine', 'pug')
|
||||
app.use(haltOnTimedout)
|
||||
|
||||
// Handle form body content
|
||||
app.use(bodyParser.urlencoded({ extended: true }))
|
||||
app.use(haltOnTimedout)
|
||||
|
||||
// Handle static assets in /public
|
||||
app.use(express.static(path.join(process.cwd(), 'public')))
|
||||
app.use(haltOnTimedout)
|
||||
|
||||
// Security middleware
|
||||
app.use(helmet())
|
||||
app.use(haltOnTimedout)
|
||||
|
||||
// Allow moment to be used in templates
|
||||
app.locals.moment = moment
|
||||
app.use(haltOnTimedout)
|
||||
|
||||
//---------------------------------------------------------
|
||||
// Routes
|
||||
|
@ -39,5 +52,4 @@ app.get('/logs', require('./routes/logs'))
|
|||
app.get('/update', require('./routes/update'))
|
||||
app.get('/', (req, res) => res.render('home', {}))
|
||||
|
||||
var server = app.listen(PORT, () => console.log('Doorlock app listening at http://localhost:3000 !'))
|
||||
server.timeout = 10000 // 10 sec is super long for our requests
|
||||
app.listen(PORT, () => console.log('Doorlock app listening at http://localhost:3000 !'))
|
||||
|
|
Loading…
Reference in New Issue
Block a user