I have restify application (simple API). We use csurf library for preventing CSRF requests.
But I need don't use CSRF validation on several routes.
First idea, which I think - this create array with routes for which I don't need use csrf and validate current route.
var routesNoCSRF = ['/api/route1', '/api/route2'];
if (routesNoCSRF.indexOf(currentRoute) === -1) {
server.use(csrf({
cookie: true,
ignoreMethods: ['HEAD', 'OPTIONS']
}));
}
But on this step I didn't have access to currentRoute
Second - this divide one API to 2 different APis - and for first use csrf validation for second - not. In this case - we create 2 different servers, which listen 2 different ports.
But i would to do this with using only one app. Is it possible ?