node.js - Use csrf only for defined routes in restify -


i have restify application (simple api). use csurf library preventing csrf requests.

but need don't use csrf validation on several routes.

first idea, think - create array routes don't need use csrf , validate current route.

var routesnocsrf = ['/api/route1', '/api/route2']; if (routesnocsrf.indexof(currentroute) === -1) {   server.use(csrf({     cookie: true,     ignoremethods: ['head', 'options']   })); } 

but on step didn't have access currentroute

second - divide 1 api 2 different apis - , first use csrf validation second - not. in case - create 2 different servers, listen 2 different ports.

but using 1 app. possible ?

there complete example ignoring routes on csurf github page.

https://github.com/expressjs/csurf


Comments

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

html - Outlook 2010 Anchor (url/address/link) -

android - How to create dynamically Fragment pager adapter -