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:
parent
a88a5c453c
commit
ede58cedb6
2 changed files with 10 additions and 2 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue