completed IoT sensor
This commit is contained in:
17
Web-Server/middleware/ApiKey.js
Normal file
17
Web-Server/middleware/ApiKey.js
Normal file
@ -0,0 +1,17 @@
|
||||
function apiKeyMiddleware(req, res, next) {
|
||||
const apiKey = req.headers['x-api-key'];
|
||||
|
||||
if (!apiKey) {
|
||||
return res.status(401).json({ error: 'API key is missing' });
|
||||
}
|
||||
|
||||
//logic to check db?
|
||||
if (apiKey !== 'YOUR_API_KEY') {
|
||||
return res.status(403).json({ error: 'Invalid API key' });
|
||||
}
|
||||
|
||||
// API key is valid, continue to the next middleware or route handler
|
||||
next();
|
||||
}
|
||||
|
||||
module.exports = apiKeyMiddleware;
|
22
Web-Server/middleware/ApiLogger.js
Normal file
22
Web-Server/middleware/ApiLogger.js
Normal file
@ -0,0 +1,22 @@
|
||||
//middleware
|
||||
|
||||
|
||||
/*
|
||||
const myLogger = function (req, res, next) {
|
||||
console.log('LOGGED')
|
||||
next()
|
||||
}
|
||||
|
||||
// Apply the middleware to a specific route
|
||||
app.use('/special-route', myLogger));
|
||||
|
||||
*/
|
||||
|
||||
const APIlogger = (req, res, next) => {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
module.exports = { }
|
Reference in New Issue
Block a user