@server/next 0.18.0 → 0.19.0
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/bucket.js +6 -0
- package/src/context/node.js +1 -0
- package/src/context/winter.js +1 -0
- package/src/parseResponse.js +1 -1
- package/src/reply.js +13 -0
package/package.json
CHANGED
package/src/bucket.js
CHANGED
|
@@ -7,6 +7,11 @@ import fsp from "fs/promises";
|
|
|
7
7
|
// at the very least a read(id) and write(id, value), both returning
|
|
8
8
|
// promises. If possible both are also pipeable/streamable.
|
|
9
9
|
export default function (root) {
|
|
10
|
+
// Already a bucket, no need to do anything with it, just return it:
|
|
11
|
+
if (typeof root !== "string") {
|
|
12
|
+
return root;
|
|
13
|
+
}
|
|
14
|
+
|
|
10
15
|
const absolute = (name) => {
|
|
11
16
|
if (!name) throw new Error(`File name is required`);
|
|
12
17
|
return path.resolve(path.join(root, name));
|
|
@@ -16,6 +21,7 @@ export default function (root) {
|
|
|
16
21
|
path: root,
|
|
17
22
|
read: (name, type = "utf8") => {
|
|
18
23
|
const fullPath = absolute(name);
|
|
24
|
+
console.log(name, fullPath);
|
|
19
25
|
return fsp.readFile(fullPath, type);
|
|
20
26
|
},
|
|
21
27
|
write: (name, value, type = "utf8") => {
|
package/src/context/node.js
CHANGED
package/src/context/winter.js
CHANGED
package/src/parseResponse.js
CHANGED
package/src/reply.js
CHANGED
|
@@ -62,6 +62,18 @@ Reply.prototype.file = async function (path) {
|
|
|
62
62
|
return status(404).send();
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
+
Reply.prototype.view = async function (path) {
|
|
66
|
+
return async (ctx) => {
|
|
67
|
+
console.log(ctx);
|
|
68
|
+
if (!ctx.options.views) {
|
|
69
|
+
throw new Error("Views not enabled");
|
|
70
|
+
}
|
|
71
|
+
const data = await ctx.options.views.read(path);
|
|
72
|
+
if (data) return this.type(path.split(".").pop()).send(data);
|
|
73
|
+
return status(404).send();
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
|
|
65
77
|
Reply.prototype.send = function (body = "") {
|
|
66
78
|
const { status = 200 } = this.res;
|
|
67
79
|
|
|
@@ -93,3 +105,4 @@ export const cookies = (...args) => new Reply().cookies(...args);
|
|
|
93
105
|
export const send = (...args) => new Reply().send(...args);
|
|
94
106
|
export const json = (...args) => new Reply().json(...args);
|
|
95
107
|
export const file = (...args) => new Reply().file(...args);
|
|
108
|
+
export const view = (...args) => new Reply().view(...args);
|