Disable CORS for 2 paths

68 views Asked by At

I'm using django-cors-header for CORS, I want to disable CORS (allow all) for 2 routes

(ex: /api/test1/, /api/test2) 

other route is still enable CORS (only allow for CORS_ORIGIN_WHITELIST host

Are there any way to do that ?

I've tried to set CORS_URLS_REGEX but then all route cannot be accessed

CORS_URLS_REGEX = r'^(?!(/api/test1/|/api/test2/).*'
1

There are 1 answers

0
ali jafarzadeh On BEST ANSWER

Try this regex. I think it can help: ^(?!(/?api/test1/?$|/?api/test2/?$)).*

I've checked this regex pattern on the website regex101 and it was okay.