sprucehttp_sjs 1.0.9 → 1.0.10
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/index.js +30 -28
- package/package.json +5 -2
package/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// This is still CommonJS to support both the old and new versions of the module system.
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
1
3
|
const fs = require("fs");
|
|
2
4
|
|
|
3
5
|
module.exports = {
|
|
@@ -6,20 +8,20 @@ module.exports = {
|
|
|
6
8
|
*
|
|
7
9
|
* Stream mode means that responses are not buffered by the webserver.
|
|
8
10
|
*/
|
|
9
|
-
streamMode: function() {
|
|
11
|
+
streamMode: function () {
|
|
10
12
|
process.send({
|
|
11
|
-
type:
|
|
13
|
+
type: "streamMode"
|
|
12
14
|
});
|
|
13
15
|
},
|
|
14
|
-
|
|
16
|
+
|
|
15
17
|
/**
|
|
16
18
|
* Writes the status line to the response.
|
|
17
19
|
* @param {number} statusCode The HTTP status code to send.
|
|
18
20
|
* @param {string} [reasonPhrase] The reason phrase to send.
|
|
19
21
|
*/
|
|
20
|
-
writeStatusLine: function(statusCode, reasonPhrase) {
|
|
22
|
+
writeStatusLine: function (statusCode, reasonPhrase) {
|
|
21
23
|
process.send({
|
|
22
|
-
type:
|
|
24
|
+
type: "status",
|
|
23
25
|
statusCode,
|
|
24
26
|
reasonPhrase
|
|
25
27
|
});
|
|
@@ -30,9 +32,9 @@ module.exports = {
|
|
|
30
32
|
* @param {string} name The name of the header to send.
|
|
31
33
|
* @param {string} value The value of the header to send.
|
|
32
34
|
*/
|
|
33
|
-
writeHeader: function(name, value) {
|
|
35
|
+
writeHeader: function (name, value) {
|
|
34
36
|
process.send({
|
|
35
|
-
type:
|
|
37
|
+
type: "header",
|
|
36
38
|
name,
|
|
37
39
|
value
|
|
38
40
|
});
|
|
@@ -44,8 +46,8 @@ module.exports = {
|
|
|
44
46
|
* When not in stream mode, the Content-Length header is automatically updated.
|
|
45
47
|
* @param {string | Buffer} data The data to send.
|
|
46
48
|
*/
|
|
47
|
-
writeData: function(data) {
|
|
48
|
-
(async () => {await this.writeDataAsync(data);})();
|
|
49
|
+
writeData: function (data) {
|
|
50
|
+
(async () => { await this.writeDataAsync(data); })();
|
|
49
51
|
},
|
|
50
52
|
|
|
51
53
|
/**
|
|
@@ -54,10 +56,10 @@ module.exports = {
|
|
|
54
56
|
* When not in stream mode, the Content-Length header is automatically updated.
|
|
55
57
|
* @param {string | Buffer} data The data to send.
|
|
56
58
|
*/
|
|
57
|
-
writeDataAsync: function(data) {
|
|
58
|
-
return new Promise(function(resolve) {
|
|
59
|
+
writeDataAsync: function (data) {
|
|
60
|
+
return new Promise(function (resolve) {
|
|
59
61
|
process.send({
|
|
60
|
-
type:
|
|
62
|
+
type: "data",
|
|
61
63
|
data: Buffer.from(data)
|
|
62
64
|
}, resolve);
|
|
63
65
|
});
|
|
@@ -69,9 +71,9 @@ module.exports = {
|
|
|
69
71
|
*
|
|
70
72
|
* This function does not work in stream mode.
|
|
71
73
|
*/
|
|
72
|
-
clearResponse: function() {
|
|
74
|
+
clearResponse: function () {
|
|
73
75
|
process.send({
|
|
74
|
-
type:
|
|
76
|
+
type: "clear"
|
|
75
77
|
});
|
|
76
78
|
},
|
|
77
79
|
|
|
@@ -80,7 +82,7 @@ module.exports = {
|
|
|
80
82
|
*
|
|
81
83
|
* @returns {{[key: string]: string}} The site-specific configuration.
|
|
82
84
|
*/
|
|
83
|
-
siteConfig: function() {
|
|
85
|
+
siteConfig: function () {
|
|
84
86
|
return JSON.parse(process.env.siteConfig);
|
|
85
87
|
},
|
|
86
88
|
|
|
@@ -89,7 +91,7 @@ module.exports = {
|
|
|
89
91
|
*
|
|
90
92
|
* @returns {string} The requestor's IP address.
|
|
91
93
|
*/
|
|
92
|
-
requestIP: function() {
|
|
94
|
+
requestIP: function () {
|
|
93
95
|
return process.env.reqIP;
|
|
94
96
|
},
|
|
95
97
|
|
|
@@ -98,8 +100,8 @@ module.exports = {
|
|
|
98
100
|
*
|
|
99
101
|
* @returns {string} The request method.
|
|
100
102
|
*/
|
|
101
|
-
method: function() {
|
|
102
|
-
return process.env.reqMethod;
|
|
103
|
+
method: function () {
|
|
104
|
+
return process.env.reqMethod.toLowerCase();
|
|
103
105
|
},
|
|
104
106
|
|
|
105
107
|
/**
|
|
@@ -107,7 +109,7 @@ module.exports = {
|
|
|
107
109
|
*
|
|
108
110
|
* @returns {string} The full request path.
|
|
109
111
|
*/
|
|
110
|
-
path: function() {
|
|
112
|
+
path: function () {
|
|
111
113
|
return process.env.reqPath;
|
|
112
114
|
},
|
|
113
115
|
|
|
@@ -116,7 +118,7 @@ module.exports = {
|
|
|
116
118
|
*
|
|
117
119
|
* @returns {string} The request's info path.
|
|
118
120
|
*/
|
|
119
|
-
pathInfo: function() {
|
|
121
|
+
pathInfo: function () {
|
|
120
122
|
return process.env.reqPathInfo;
|
|
121
123
|
},
|
|
122
124
|
|
|
@@ -125,7 +127,7 @@ module.exports = {
|
|
|
125
127
|
*
|
|
126
128
|
* @returns {{[key: string]: string}} The parsed query string of the request.
|
|
127
129
|
*/
|
|
128
|
-
query: function() {
|
|
130
|
+
query: function () {
|
|
129
131
|
return JSON.parse(process.env.reqQuery || "{}");
|
|
130
132
|
},
|
|
131
133
|
|
|
@@ -135,7 +137,7 @@ module.exports = {
|
|
|
135
137
|
* @param {string} key The key of the query to get.
|
|
136
138
|
* @returns {string} The value of the query parameter.
|
|
137
139
|
*/
|
|
138
|
-
queryValue: function(key) {
|
|
140
|
+
queryValue: function (key) {
|
|
139
141
|
return this.query()[key];
|
|
140
142
|
},
|
|
141
143
|
|
|
@@ -144,7 +146,7 @@ module.exports = {
|
|
|
144
146
|
*
|
|
145
147
|
* @returns {string} The HTTP version of the request.
|
|
146
148
|
*/
|
|
147
|
-
httpVersion: function() {
|
|
149
|
+
httpVersion: function () {
|
|
148
150
|
return process.env.reqHttpVersion;
|
|
149
151
|
},
|
|
150
152
|
|
|
@@ -153,7 +155,7 @@ module.exports = {
|
|
|
153
155
|
*
|
|
154
156
|
* @returns {{[key: string]: string}} The headers of the request.
|
|
155
157
|
*/
|
|
156
|
-
headers: function() {
|
|
158
|
+
headers: function () {
|
|
157
159
|
return JSON.parse(process.env.reqHeaders || "{}");
|
|
158
160
|
},
|
|
159
161
|
|
|
@@ -163,7 +165,7 @@ module.exports = {
|
|
|
163
165
|
* @param {string} name The name of the header to get.
|
|
164
166
|
* @returns {string} The value of the header.
|
|
165
167
|
*/
|
|
166
|
-
headerValue: function(name) {
|
|
168
|
+
headerValue: function (name) {
|
|
167
169
|
return this.headers()[name];
|
|
168
170
|
},
|
|
169
171
|
|
|
@@ -172,7 +174,7 @@ module.exports = {
|
|
|
172
174
|
*
|
|
173
175
|
* @returns {Buffer} The body of the request.
|
|
174
176
|
*/
|
|
175
|
-
body: function() {
|
|
177
|
+
body: function () {
|
|
176
178
|
let retVal = undefined;
|
|
177
179
|
if (process.env.reqBody) {
|
|
178
180
|
retVal = fs.readFileSync(process.env.reqBody);
|
|
@@ -186,11 +188,11 @@ module.exports = {
|
|
|
186
188
|
* @param {string | Object} [options] The options to pass to fs.createReadStream.
|
|
187
189
|
* @returns {fs.ReadStream} A ReadStream of the body of the request.
|
|
188
190
|
*/
|
|
189
|
-
|
|
191
|
+
bodyStream: function (options) {
|
|
190
192
|
let retVal = undefined;
|
|
191
193
|
if (process.env.reqBody) {
|
|
192
194
|
retVal = fs.createReadStream(process.env.reqBody, options);
|
|
193
195
|
}
|
|
194
196
|
return retVal;
|
|
195
197
|
}
|
|
196
|
-
}
|
|
198
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sprucehttp_sjs",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "A module for responding to requests within SpruceHTTP in an SJS file",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,5 +23,8 @@
|
|
|
23
23
|
"email": "herronjo@stibarc.dev",
|
|
24
24
|
"url": "https://stibarc.dev"
|
|
25
25
|
},
|
|
26
|
-
"license": "Copyright (c) STiBaRC LLC. All rights reserved."
|
|
26
|
+
"license": "Copyright (c) STiBaRC LLC. All rights reserved.",
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"sprucehttp_sjs": "file:"
|
|
29
|
+
}
|
|
27
30
|
}
|