Just in case anyone else arrives here after all this time, there's a slightly simpler solution, for cases like mine anyway: the csrf
check will not be invoked if the submission doesn't have a Content-Type
header that looks like a form. From the code, this function needs to return true to enable the check:
function is_form_content_type(request) {
return is_content_type(
request,
"application/x-www-form-urlencoded",
"multipart/form-data",
"text/plain"
);
}
In my case I am working on a backend server api, so setting Content-Type
to application/json
allowed the request to proceed.
Note this is SvelteKit server code, and is not dependant on the adapter you're using.
$env:ORIGIN = "http://127.0.0.1"
and runnode build/index.js
on the next line, because for some reason, powershell does not notice the change in env var when the env var is changed and the build command is run on the same line. – Audient