1
0
Fork 0

fix(backend): Load index page on startup

Previous code would load the page (from disk) on each request
which facilitates denial-of-service attacks.
This commit is contained in:
Joost De Cock 2022-02-05 09:02:26 +01:00
parent a88a5c453c
commit ede58cedb6
2 changed files with 10 additions and 2 deletions

View file

@ -9,6 +9,7 @@ import expressMiddleware from './middleware/express'
import passportMiddleware from './middleware/passport'
import routes from './routes'
import path from 'path'
import fs from 'fs'
// Verify configuration
verifyConfig(config, chalk)
@ -39,8 +40,13 @@ mongoose
process.exit()
})
// Catch-all route
app.get('/', async (req, res) => res.sendFile(path.resolve(__dirname, 'landing', 'index.html')))
// Catch-all route (Load index.html once instead of at every request)
const index = fs.readFileSync(path.resolve(__dirname, 'landing', 'index.html'))
app.get('/', async (req, res) => res
.set('Content-Type', 'text/html')
.status(200)
.send(index)
)
const port = process.env.PORT || 3000