@server/next 0.21.14 → 0.22.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/helpers/types.js +2 -0
- package/src/reply.js +16 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@server/next",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"description": "A fully-fledged web server with routing, file uploads, sessions, static files, schema validation, websockets, testing, etc.",
|
|
5
5
|
"homepage": "https://server-js.com/",
|
|
6
6
|
"repository": "https://github.com/franciscop/server-next.git",
|
package/src/helpers/types.js
CHANGED
|
@@ -30,6 +30,7 @@ export default {
|
|
|
30
30
|
js: "text/javascript",
|
|
31
31
|
json: "application/json",
|
|
32
32
|
jsonld: "application/ld+json",
|
|
33
|
+
md: "text/markdown",
|
|
33
34
|
mid: "audio/midi",
|
|
34
35
|
midi: "audio/midi",
|
|
35
36
|
mjs: "text/javascript",
|
|
@@ -55,6 +56,7 @@ export default {
|
|
|
55
56
|
sh: "application/x-sh",
|
|
56
57
|
svg: "image/svg+xml",
|
|
57
58
|
tar: "application/x-tar",
|
|
59
|
+
text: "text/plain",
|
|
58
60
|
tif: "image/tiff",
|
|
59
61
|
tiff: "image/tiff",
|
|
60
62
|
ts: "video/mp2t",
|
package/src/reply.js
CHANGED
|
@@ -27,8 +27,20 @@ Reply.prototype.status = function (status) {
|
|
|
27
27
|
// `.html`, `html`, `text/html`
|
|
28
28
|
Reply.prototype.type = function (type) {
|
|
29
29
|
if (!type) return this;
|
|
30
|
-
|
|
31
|
-
return this;
|
|
30
|
+
type = types[type.replace(/^\./)] || type;
|
|
31
|
+
return this.headers({ "content-type": type });
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// Prompt for download from the user side
|
|
35
|
+
Reply.prototype.download = function (name = "", type) {
|
|
36
|
+
// filename.txt and no explicit type => add headers "text/plain"
|
|
37
|
+
if (name && !ext) type = name.split(".")[1];
|
|
38
|
+
|
|
39
|
+
// Add the Content-Type if there's a type
|
|
40
|
+
if (type) this.type(type);
|
|
41
|
+
|
|
42
|
+
const filename = name ? `; filename="${name}"` : "";
|
|
43
|
+
return this.headers({ "content-disposition": `attachment${filename}` });
|
|
32
44
|
};
|
|
33
45
|
|
|
34
46
|
// Set extra headers
|
|
@@ -127,8 +139,9 @@ export { Reply };
|
|
|
127
139
|
|
|
128
140
|
// PARTIAL
|
|
129
141
|
export const status = (...args) => new Reply().status(...args);
|
|
130
|
-
export const type = (...args) => new Reply().type(...args);
|
|
131
142
|
export const headers = (...args) => new Reply().headers(...args);
|
|
143
|
+
export const type = (...args) => new Reply().type(...args);
|
|
144
|
+
export const download = (...args) => new Reply().download(...args);
|
|
132
145
|
export const cookies = (...args) => new Reply().cookies(...args);
|
|
133
146
|
|
|
134
147
|
// FINAL
|