@server/next 0.20.12 → 0.20.13
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 +1 -1
- package/src/index.js +1 -0
- package/src/middle/assets.js +2 -1
- package/src/parseResponse.js +8 -0
- package/src/pathPattern.js +2 -0
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -50,6 +50,7 @@ const createNodeServer = async (app, options) => {
|
|
|
50
50
|
const validateOptions = (options, env = {}) => {
|
|
51
51
|
options.port = options.port || env.PORT || 3000;
|
|
52
52
|
options.secret = options.secret || env.SECRET || "unsafe-" + createId();
|
|
53
|
+
options.cors = options.cors || env.CORS || null;
|
|
53
54
|
|
|
54
55
|
options.views = options.views ? Bucket(options.views) : null;
|
|
55
56
|
options.public = options.public ? Bucket(options.public) : null;
|
package/src/middle/assets.js
CHANGED
|
@@ -3,7 +3,8 @@ import { type } from "../reply.js";
|
|
|
3
3
|
export default async function assets(ctx) {
|
|
4
4
|
try {
|
|
5
5
|
// TODO: streaming
|
|
6
|
-
|
|
6
|
+
// Read it as buffer (null)
|
|
7
|
+
const asset = await ctx.options.public.read(ctx.url.pathname, null);
|
|
7
8
|
if (!asset) return;
|
|
8
9
|
return type(ctx.url.pathname.split(".").pop()).send(asset);
|
|
9
10
|
} catch (error) {
|
package/src/parseResponse.js
CHANGED
|
@@ -39,6 +39,14 @@ export default async function parseResponse(out, ctx) {
|
|
|
39
39
|
|
|
40
40
|
// Here it should be a Response
|
|
41
41
|
|
|
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";
|
|
46
|
+
out.headers.set("Access-Control-Allow-Origin", origin);
|
|
47
|
+
out.headers.set("Access-Control-Allow-Methods", methods);
|
|
48
|
+
}
|
|
49
|
+
|
|
42
50
|
// If we have a session, we need to persist it into a cookie
|
|
43
51
|
if (Object.keys(ctx.session || {}).length) {
|
|
44
52
|
if (!ctx.options.session?.store) {
|