use real timeouts (10s)

This commit is contained in:
Will Bradley 2018-09-01 16:43:26 -07:00
parent bee518e1ef
commit ad1d060cdc
No known key found for this signature in database
GPG Key ID: 42BAE225DDDB7093
3 changed files with 82 additions and 2 deletions

67
package-lock.json generated
View File

@ -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": { "dotenv": {
"version": "5.0.1", "version": "5.0.1",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-5.0.1.tgz", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-5.0.1.tgz",

View File

@ -12,6 +12,7 @@
"axios": "0.18.0", "axios": "0.18.0",
"body-parser": "1.18.3", "body-parser": "1.18.3",
"chalk": "2.3.1", "chalk": "2.3.1",
"connect-timeout": "^1.9.0",
"dotenv": "5.0.1", "dotenv": "5.0.1",
"easy-usb-relay": "0.0.4", "easy-usb-relay": "0.0.4",
"express": "4.16.3", "express": "4.16.3",

View File

@ -5,27 +5,40 @@ const moment = require('moment')
const path = require('path') const path = require('path')
const app = express() const app = express()
const timeout = require('connect-timeout')
function haltOnTimedout (req, res, next) {
if (!req.timedout) next()
}
const PORT = process.env.PORT || 3000 const PORT = process.env.PORT || 3000
//--------------------------------------------------------- //---------------------------------------------------------
// Middleware // Middleware
//--------------------------------------------------------- //---------------------------------------------------------
// Time out after 10 secs
app.use(timeout('10s'))
// View engine setup // View engine setup
app.set('views', path.join(process.cwd(), 'src', 'views')) app.set('views', path.join(process.cwd(), 'src', 'views'))
app.set('view engine', 'pug') app.set('view engine', 'pug')
app.use(haltOnTimedout)
// Handle form body content // Handle form body content
app.use(bodyParser.urlencoded({ extended: true })) app.use(bodyParser.urlencoded({ extended: true }))
app.use(haltOnTimedout)
// Handle static assets in /public // Handle static assets in /public
app.use(express.static(path.join(process.cwd(), 'public'))) app.use(express.static(path.join(process.cwd(), 'public')))
app.use(haltOnTimedout)
// Security middleware // Security middleware
app.use(helmet()) app.use(helmet())
app.use(haltOnTimedout)
// Allow moment to be used in templates // Allow moment to be used in templates
app.locals.moment = moment app.locals.moment = moment
app.use(haltOnTimedout)
//--------------------------------------------------------- //---------------------------------------------------------
// Routes // Routes
@ -39,5 +52,4 @@ app.get('/logs', require('./routes/logs'))
app.get('/update', require('./routes/update')) app.get('/update', require('./routes/update'))
app.get('/', (req, res) => res.render('home', {})) app.get('/', (req, res) => res.render('home', {}))
var server = app.listen(PORT, () => console.log('Doorlock app listening at http://localhost:3000 !')) app.listen(PORT, () => console.log('Doorlock app listening at http://localhost:3000 !'))
server.timeout = 10000 // 10 sec is super long for our requests