Code files
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
'use strict'
|
||||
|
||||
const express = require('express')
|
||||
const app = express()
|
||||
|
||||
function validate ({prev, handoverToken, lang}, query) {
|
||||
var valid = Object.keys(query).length <= 3
|
||||
valid = valid && typeof lang === 'string' && lang.length === 2
|
||||
valid = valid && typeof handoverToken === 'string' && handoverToken.length === 16
|
||||
valid = valid && typeof prev === 'string' && prev.length < 10
|
||||
return valid
|
||||
}
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
const {prev = '', handoverToken = '', lang = 'en'} = req.query
|
||||
|
||||
if (!validate({prev, handoverToken, lang}, req.query)) {
|
||||
res.sendStatus(422)
|
||||
return
|
||||
}
|
||||
|
||||
pretendDbQuery((err, status) => {
|
||||
if (err) {
|
||||
res.sendStatus(500)
|
||||
return
|
||||
}
|
||||
res.send(`
|
||||
<h1>Current Status</h1>
|
||||
<div id=stat>
|
||||
${status}
|
||||
</div>
|
||||
<div>
|
||||
<a href="${prev}${handoverToken}/${lang}"> Back to Control HQ </a>
|
||||
</div>
|
||||
`)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
function pretendDbQuery (cb) {
|
||||
const status = 'ON FIRE!!! HELP!!!'
|
||||
cb(null, status)
|
||||
}
|
||||
|
||||
|
||||
app.listen(3000)
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "app",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"escape-html": "^1.0.3",
|
||||
"express": "^4.15.2"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user