kit icon indicating copy to clipboard operation
kit copied to clipboard

Custom Server ( express ) throwing CORS error

Open bobthered opened this issue 4 years ago • 3 comments

Describe the bug

When using a custom node server, CORS errors are returned from form submissions to actions endpoint.

Reproduction

@bobthered/sveltekit-issue-custom-server-cors

Logs

No response

System Info

System:
    OS: macOS Mojave 10.14.6
    CPU: (4) x64 Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz
    Memory: 996.74 MB / 8.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 16.15.1 - /usr/local/bin/node
    npm: 8.19.2 - /usr/local/bin/npm
  Browsers:
    Chrome: 105.0.5195.125
    Safari: 12.1.2
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.80 
    @sveltejs/adapter-node: ^1.0.0-next.96 => 1.0.0-next.96 
    @sveltejs/kit: next => 1.0.0-next.504 
    svelte: ^3.44.0 => 3.50.1 
    vite: ^3.1.0 => 3.1.3

Severity

blocking all usage of SvelteKit

Additional Information

No response

bobthered avatar Sep 26 '22 17:09 bobthered

Don't have experience with custom server, nor am I understanding the use case in sveltekit(I would love learn tho ). That aside, have you tried passing cors some configuration? Edit: Maybe

const corsOptions = {
    origin:'*', 
    credentials:true,            //access-control-allow-credentials:true
    optionSuccessStatus:200,
 }
app.use(cors(corsOptions))

Also the form in the reproduction is missing the method

MCole-K9 avatar Sep 26 '22 19:09 MCole-K9

did you try installing the cors package?

AiHKhaled avatar Oct 02 '22 01:10 AiHKhaled

I assume you're referring to this?

Cross-site POST form submissions are forbidden

I suspect this is happening because you don't have an ORIGIN set: https://github.com/sveltejs/kit/tree/master/packages/adapter-node#environment-variables

Rich-Harris avatar Nov 16 '22 21:11 Rich-Harris