Auth hooks - codehooks.io

import app from 'codehooks-js'; // Standard JS lib for express style code

// REST API routes
app.get('/specialroute/frags', (req, res) => {
res.end('You have the correct secret header value');
});

// Auth hook
app.auth('/specialroute/*', (req, res, next) => {
// call some auth function here, e.g. myLookup
myLookup(req.headers['X-challenge'], (err, data) => {
if (err) {
res.status(401); // Unauthorized
res.end();
} else {
// allow API call
next();
}
});
});

function myLookup(challenge, callback) {
if (challenge === 'SOMESECRET') {
callback(null);
} else {
callback('Sorry');
}
}

export default app.init(); // Bind functions to the serverless runtime