franciscop / server

:desktop_computer: Simple and powerful server for Node.js
https://serverjs.io/
MIT License
3.56k stars 171 forks source link

Add CORS package to the core #141

Open franciscop opened 2 years ago

franciscop commented 2 years ago

Is your feature request related to a problem? Please describe. One of the basic features of APIs is to be able to work nicely with CORS. This is not possible with Server.js, and instead you need to either install a third party package or do it manually.

Describe the solution you'd like Have the cors package be a part of the core. It should be disabled by default, but easily be able to do:

server({ cors: false });   // Default (to keep it retro-compatible)
server({ cors: "*" });
server({ cors: "https://serverjs.io" });
server({ cors: ["https://serverjs.io", "http://localhost:3000"] });
server({
  cors: { origin: "https://serverjs.io",  methods: ["GET", "PUT", "POST"] }
});

Describe alternatives you've considered Using the cors package; it'd be nice to have it in the core so we don't need to install it each time.

Additional context Since server.js is supposed to work nicely both as an API server and as a renderer (traditional) server, this makes making an API easier.

ghost commented 10 months ago

Whatever it takes to receive all text messages. Please help