@server/next 0.20.14 → 0.20.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@server/next",
3
- "version": "0.20.14",
3
+ "version": "0.20.15",
4
4
  "description": "An experimental reimplementation of server.js focused on the DX",
5
5
  "homepage": "https://node-server.com/",
6
6
  "repository": "https://github.com/franciscop/server-next.git",
package/src/index.js CHANGED
@@ -51,6 +51,15 @@ const validateOptions = (options, env = {}) => {
51
51
  options.port = options.port || env.PORT || 3000;
52
52
  options.secret = options.secret || env.SECRET || "unsafe-" + createId();
53
53
  options.cors = options.cors || env.CORS || null;
54
+ if (options.cors === true) {
55
+ options.cors = { origin: options.domain || "*" };
56
+ }
57
+ if (typeof options.cors === "string") {
58
+ options.cors = { origin: options.cors };
59
+ }
60
+ if (options.cors && !options.cors.methods) {
61
+ options.cors.methods = "GET,HEAD,POST,PUT,PATCH";
62
+ }
54
63
 
55
64
  options.views = options.views ? Bucket(options.views) : null;
56
65
  options.public = options.public ? Bucket(options.public) : null;
@@ -40,9 +40,8 @@ export default async function parseResponse(out, ctx) {
40
40
  // Here it should be a Response
41
41
 
42
42
  // If we have CORS, set it up
43
- if (typeof ctx.options.cors === "string") {
44
- const origin = ctx.options.cors || ctx.options.domain || "*";
45
- const methods = "GET,HEAD,POST,PUT,PATCH";
43
+ if (ctx.options.cors) {
44
+ const { origin, methods } = ctx.options.cors;
46
45
  out.headers.set("Access-Control-Allow-Origin", origin);
47
46
  out.headers.set("Access-Control-Allow-Methods", methods);
48
47
  }