Serve: Cors option?

Created on 30 May 2018  路  12Comments  路  Source: vercel/serve

Hey, I use serve every day so thanks for the continued maintenance :-)

The latest update seems to have removed the cors option from the cli, was that intentional?

Most helpful comment

Gotcha, thanks.

I will say this makes the tool less convenient for me as I use it to quickly serve up a local folder with npx serve <dir> --cors. With the CLI option I don't need to add any extra configuration specific to serve for each project.

Just my 2 cents though! I'm very likely in the minority of people who used the --cors option frequently.

My workaround for now is to just use the older version as it works perfectly fine for my use case npx [email protected] --cors <dir>

Cheers!

All 12 comments

Yes! 馃槉

Please use the new headers option in serve.json to apply any CORS headers:

https://github.com/zeit/serve-handler#headers-array

Gotcha, thanks.

I will say this makes the tool less convenient for me as I use it to quickly serve up a local folder with npx serve <dir> --cors. With the CLI option I don't need to add any extra configuration specific to serve for each project.

Just my 2 cents though! I'm very likely in the minority of people who used the --cors option frequently.

My workaround for now is to just use the older version as it works perfectly fine for my use case npx [email protected] --cors <dir>

Cheers!

@jschr thanks for the work around! 馃憤 for adding the command line option back

Thanks, I also ended up rolling back to 6.5.8. I love serve's simplicity and I use it mainly in dev, so I also find the need to provide a JSON configuration file to get CORS to work quite inconvenient...

$ cat serve.json
{
  "headers": [
    { "source" : "**/*.@(jpg|jpeg|gif|png|txt)"
    , "headers" :
        [{ "key" : "Access-Control-Allow-Origin"
         , "value" : "*"
         }
        ,{ "key" : "Access-Control-Allow-Headers"
         , "value" : "Origin, X-Requested-With, Content-Type, Accept, Range"
         }
        ]
    }
  ]
}

$ serve
INFO: Discovered configuration in `serve.json`
INFO: Accepting connections at http://localhost:5000

Still using npx [email protected] --cors for a quick way to use cors without creating a config file. I don't know if this is up for debate, but I'd love to have the --cors flag in the latest version.

Yeah likewise, I don't get this craving for config files.

Thanks for pointing out serve@6.

Just thought I'd update this issue. I've been using https://github.com/indexzero/http-server instead now.

This packaged worked great as as quick and easy CLI tool but seems to not be interested in that use case anymore.

@jschr awesome thanks for suggesting a usable alternative!! 馃檹馃徑

@sebbean And this is how you make it work with SPA navigation https://github.com/indexzero/http-server/issues/519#issuecomment-487614367

live-server also does the trick (has a --cors option), and as a bonus can automatically refresh your web page on file changes if you specify --watch (or --watch=patterns to watch certain files).

It's back!

Thanks for the feedback.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gaearon picture gaearon  路  4Comments

nermin99 picture nermin99  路  3Comments

lightzane picture lightzane  路  5Comments

Mugen87 picture Mugen87  路  3Comments

k7sleeper picture k7sleeper  路  7Comments