http-server icon indicating copy to clipboard operation
http-server copied to clipboard

CORS | Support for multiple origins

Open LeoBorai opened this issue 3 years ago • 0 comments

Description

Capability to allow several origins, instead of providing wildcard (*), a list of origins could be configured to be accepted by the server.

When a request is gathered from the client, the origin is checked against the provided list and if such origin belongs to the list, then the CORS Allow-Origin header would have such origin settled as value.

Why is this useful?

This could help for serving files to multiple front-ends but not any

How should this work?

  1. CORS configuration is provided via TOML config file
  2. A list of origins is set to the allowed_origins list in the configuration file
  3. When a request hits this server, the origin from the HTTP Request is checked against the allowed_origins setting 3.1. If the origin of the HTTP Request belongs to the list, the Access-Control-Allow-Origin header is set to such origin 3.2. Otherwise the Access-Control-Allow-Origin header is not included in the HTTP Response

This feature request was originally mentioned by @morenol in the following PR comment:

https://github.com/EstebanBorai/http-server/pull/7#discussion_r627737889

LeoBorai avatar May 10 '21 04:05 LeoBorai