sprucehttp_sjs 1.0.6 → 1.0.9
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/README.md +28 -0
- package/index.js +26 -0
- package/package.json +27 -27
package/README.md
CHANGED
|
@@ -9,6 +9,7 @@ A module for responding to requests within SpruceHTTP in an SJS file.
|
|
|
9
9
|
- [writeHeader(name, value)](#writeheadername-value)
|
|
10
10
|
- [writeData(data)](#writedatadata)
|
|
11
11
|
- [writeDataAsync(data)](#writedataasyncdata)
|
|
12
|
+
- [clearResponse()](#clearresponse)
|
|
12
13
|
- [siteConfig()](#siteconfig)
|
|
13
14
|
- [requestIP()](#requestip)
|
|
14
15
|
- [method()](#method)
|
|
@@ -20,6 +21,7 @@ A module for responding to requests within SpruceHTTP in an SJS file.
|
|
|
20
21
|
- [headers()](#headers)
|
|
21
22
|
- [headerValue(name)](#headervaluename)
|
|
22
23
|
- [body()](#body)
|
|
24
|
+
- [bodyStream()](#bodystream)
|
|
23
25
|
|
|
24
26
|
## Documentation:
|
|
25
27
|
Importing the module:
|
|
@@ -95,6 +97,24 @@ const fs = require('fs');
|
|
|
95
97
|
await sjs.writeDataAsync(fs.readFileSync("image.png", 'binary'));
|
|
96
98
|
```
|
|
97
99
|
|
|
100
|
+
### ``clearResponse()``:
|
|
101
|
+
Clears the currently written response and resets the status line, headers, and body.
|
|
102
|
+
This is useful when you want to send a different response than the one you have already written.
|
|
103
|
+
|
|
104
|
+
This function does not work in stream mode.
|
|
105
|
+
|
|
106
|
+
```js
|
|
107
|
+
sjs.writeStatusLine(418, "I'm a teapot");
|
|
108
|
+
sjs.writeHeader("Content-Type", "text/html");
|
|
109
|
+
sjs.writeData("<h1>I'm a teapot</h1>");
|
|
110
|
+
// Be serious
|
|
111
|
+
sjs.clearResponse();
|
|
112
|
+
|
|
113
|
+
sjs.writeStatusLine(200);
|
|
114
|
+
sjs.writeHeader("Content-Type", "text/html");
|
|
115
|
+
sjs.writeData("<h1>I'm <i>not</i> a teapot</h1>");
|
|
116
|
+
```
|
|
117
|
+
|
|
98
118
|
### ``siteConfig()``:
|
|
99
119
|
Returns the site-specific configuration set in your config file.
|
|
100
120
|
|
|
@@ -217,4 +237,12 @@ Returns the request body as a buffer.
|
|
|
217
237
|
```js
|
|
218
238
|
console.log(sjs.body().toString("utf8"));
|
|
219
239
|
// Hello, world!
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### ``bodyStream()``:
|
|
243
|
+
Returns the request body as a ReadStream.
|
|
244
|
+
|
|
245
|
+
```js
|
|
246
|
+
console.log(sjs.bodyStream().read(13).toString("utf8"));
|
|
247
|
+
// Hello, world!
|
|
220
248
|
```
|
package/index.js
CHANGED
|
@@ -63,6 +63,18 @@ module.exports = {
|
|
|
63
63
|
});
|
|
64
64
|
},
|
|
65
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Clears the currently written response and resets the status line, headers, and body.
|
|
68
|
+
* This is useful when you want to send a different response than the one you have already written.
|
|
69
|
+
*
|
|
70
|
+
* This function does not work in stream mode.
|
|
71
|
+
*/
|
|
72
|
+
clearResponse: function() {
|
|
73
|
+
process.send({
|
|
74
|
+
type: 'clear'
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
|
|
66
78
|
/**
|
|
67
79
|
* Returns the site-specific configuration.
|
|
68
80
|
*
|
|
@@ -166,5 +178,19 @@ module.exports = {
|
|
|
166
178
|
retVal = fs.readFileSync(process.env.reqBody);
|
|
167
179
|
}
|
|
168
180
|
return retVal;
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Returns the body of the request as an fs.ReadStream.
|
|
185
|
+
*
|
|
186
|
+
* @param {string | Object} [options] The options to pass to fs.createReadStream.
|
|
187
|
+
* @returns {fs.ReadStream} A ReadStream of the body of the request.
|
|
188
|
+
*/
|
|
189
|
+
bodyStream: function(options) {
|
|
190
|
+
let retVal = undefined;
|
|
191
|
+
if (process.env.reqBody) {
|
|
192
|
+
retVal = fs.createReadStream(process.env.reqBody, options);
|
|
193
|
+
}
|
|
194
|
+
return retVal;
|
|
169
195
|
}
|
|
170
196
|
}
|
package/package.json
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "sprucehttp_sjs",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "A module for responding to requests within SpruceHTTP in an SJS file",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
-
},
|
|
9
|
-
"keywords": [
|
|
10
|
-
"http",
|
|
11
|
-
"server",
|
|
12
|
-
"https",
|
|
13
|
-
"spruce",
|
|
14
|
-
"sprucehttp"
|
|
15
|
-
],
|
|
16
|
-
"homepage": "https://stibarc.dev/spruce/",
|
|
17
|
-
"bugs": {
|
|
18
|
-
"url": "https://stibarc.dev/spruce/reportbug/",
|
|
19
|
-
"email": "herronjo@stibarc.dev"
|
|
20
|
-
},
|
|
21
|
-
"author": {
|
|
22
|
-
"name": "Joshua Herron",
|
|
23
|
-
"email": "herronjo@stibarc.dev",
|
|
24
|
-
"url": "https://stibarc.dev"
|
|
25
|
-
},
|
|
26
|
-
"license": "Copyright (c) STiBaRC LLC. All rights reserved."
|
|
27
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "sprucehttp_sjs",
|
|
3
|
+
"version": "1.0.9",
|
|
4
|
+
"description": "A module for responding to requests within SpruceHTTP in an SJS file",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"http",
|
|
11
|
+
"server",
|
|
12
|
+
"https",
|
|
13
|
+
"spruce",
|
|
14
|
+
"sprucehttp"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://stibarc.dev/spruce/",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://stibarc.dev/spruce/reportbug/",
|
|
19
|
+
"email": "herronjo@stibarc.dev"
|
|
20
|
+
},
|
|
21
|
+
"author": {
|
|
22
|
+
"name": "Joshua Herron",
|
|
23
|
+
"email": "herronjo@stibarc.dev",
|
|
24
|
+
"url": "https://stibarc.dev"
|
|
25
|
+
},
|
|
26
|
+
"license": "Copyright (c) STiBaRC LLC. All rights reserved."
|
|
27
|
+
}
|