- Added the magic mystery key wooo

This commit is contained in:
Alexis
2020-06-15 22:16:53 +02:00
parent b543197021
commit 82bbf9f7bb
14 changed files with 94 additions and 34 deletions

View File

@@ -6,6 +6,7 @@ const bodyParser = require('body-parser')
const helmet = require('helmet')
const morgan = require('morgan')
const cors = require('cors') // module to format the json response
const dotenv = require('dotenv').config()
// Creates instances of database connections
const connection = require('./database/bookshelf')
@@ -27,6 +28,15 @@ app.use(helmet())
// Serves
const server = app.listen( port, () => {console.log(`App listening on port ${port}`)})
// Auth
app.all('*', (req, res, next) => {
if (req.headers.auracle_key !== process.env.API_KEY) {
return res.status(401).send('The API is either missing or incorrect.')
} else {
next()
}
})
// Routing
app.use('/api/spells', routes.spells)
app.use('/api/schools', routes.schools)
@@ -34,3 +44,4 @@ app.use('/api/meta_schools', routes.meta_schools)
app.use('/api/variables', routes.variables)
app.use('/api/ingredients', routes.ingredients)
app.use('/api/users', routes.users)