sprucehttp_sjs 1.0.8 → 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 +19 -0
- package/index.js +12 -0
- package/package.json +1 -1
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)
|
|
@@ -96,6 +97,24 @@ const fs = require('fs');
|
|
|
96
97
|
await sjs.writeDataAsync(fs.readFileSync("image.png", 'binary'));
|
|
97
98
|
```
|
|
98
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
|
+
|
|
99
118
|
### ``siteConfig()``:
|
|
100
119
|
Returns the site-specific configuration set in your config file.
|
|
101
120
|
|
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
|
*
|