temba 0.7.8 → 0.7.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/dist/config/index.js +6 -1
- package/dist/delay/middleware.js +16 -0
- package/dist/server.js +9 -1
- package/package.json +2 -1
- package/readme.md +9 -7
package/dist/config/index.js
CHANGED
|
@@ -22,7 +22,8 @@ var defaultConfig = {
|
|
|
22
22
|
staticFolder: null,
|
|
23
23
|
apiPrefix: '',
|
|
24
24
|
connectionString: null,
|
|
25
|
-
cacheControl: 'no-store'
|
|
25
|
+
cacheControl: 'no-store',
|
|
26
|
+
delay: 2000
|
|
26
27
|
};
|
|
27
28
|
|
|
28
29
|
function initConfig(userConfig) {
|
|
@@ -55,5 +56,9 @@ function initConfig(userConfig) {
|
|
|
55
56
|
config.cacheControl = userConfig.cacheControl;
|
|
56
57
|
}
|
|
57
58
|
|
|
59
|
+
if (userConfig.delay && userConfig.delay.length !== 0 && typeof Number(userConfig.delay) === 'number' && Number(userConfig.delay) > 0 && Number(userConfig.delay) < 10000) {
|
|
60
|
+
config.delay = Number(userConfig.delay);
|
|
61
|
+
}
|
|
62
|
+
|
|
58
63
|
return config;
|
|
59
64
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createDelayMiddleware = createDelayMiddleware;
|
|
7
|
+
|
|
8
|
+
var pause = require('connect-pause');
|
|
9
|
+
|
|
10
|
+
function createDelayMiddleware(delay) {
|
|
11
|
+
return function (req, res, next) {
|
|
12
|
+
console.log('Start delay...');
|
|
13
|
+
pause(delay)(req, res, next);
|
|
14
|
+
console.log('Delay finished!');
|
|
15
|
+
};
|
|
16
|
+
}
|
package/dist/server.js
CHANGED
|
@@ -23,6 +23,8 @@ var _config = require("./config");
|
|
|
23
23
|
|
|
24
24
|
var _cors = _interopRequireDefault(require("cors"));
|
|
25
25
|
|
|
26
|
+
var _middleware2 = require("./delay/middleware");
|
|
27
|
+
|
|
26
28
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
27
29
|
|
|
28
30
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -38,7 +40,13 @@ function createServer(userConfig) {
|
|
|
38
40
|
app.use((0, _cors["default"])({
|
|
39
41
|
origin: true,
|
|
40
42
|
credentials: true
|
|
41
|
-
}));
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
if (config.delay > 0) {
|
|
46
|
+
var delayMiddleware = (0, _middleware2.createDelayMiddleware)(config.delay);
|
|
47
|
+
app.use(delayMiddleware);
|
|
48
|
+
} // Serve a static folder, if configured.
|
|
49
|
+
|
|
42
50
|
|
|
43
51
|
if (config.staticFolder) {
|
|
44
52
|
app.use(_express["default"]["static"](config.staticFolder));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "temba",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.9",
|
|
4
4
|
"description": "Get a simple MongoDB REST API with zero coding in less than 30 seconds (seriously).",
|
|
5
5
|
"main": "dist/server.js",
|
|
6
6
|
"scripts": {
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@babel/runtime": "^7.15.4",
|
|
33
33
|
"@rakered/mongo": "^1.6.0",
|
|
34
|
+
"connect-pause": "^0.1.0",
|
|
34
35
|
"cors": "^2.8.5",
|
|
35
36
|
"express": "^4.17.1",
|
|
36
37
|
"morgan": "^1.10.0"
|
package/readme.md
CHANGED
|
@@ -155,19 +155,21 @@ const config = {
|
|
|
155
155
|
staticFolder: 'build',
|
|
156
156
|
apiPrefix: 'api',
|
|
157
157
|
cacheControl: 'public, max-age=300',
|
|
158
|
+
delay: 500,
|
|
158
159
|
}
|
|
159
160
|
const server = temba.create(config)
|
|
160
161
|
```
|
|
161
162
|
|
|
162
163
|
These are all the possible settings:
|
|
163
164
|
|
|
164
|
-
| Config setting | Description
|
|
165
|
-
| :----------------- |
|
|
166
|
-
| `resourceNames` | See [Allowing specific resources only](#allowing-specific-resources-only)
|
|
167
|
-
| `connectionString` | See [MongoDB](#mongodb)
|
|
168
|
-
| `staticFolder` | See [Static assets](#static-assets)
|
|
169
|
-
| `apiPrefix` | See [REST URIs prefixes](#rest-uris-prefixes)
|
|
170
|
-
| `cacheControl` | The `Cache-control` response header value for each GET request.
|
|
165
|
+
| Config setting | Description |
|
|
166
|
+
| :----------------- | :----------------------------------------------------------------------------------------- |
|
|
167
|
+
| `resourceNames` | See [Allowing specific resources only](#allowing-specific-resources-only) |
|
|
168
|
+
| `connectionString` | See [MongoDB](#mongodb) |
|
|
169
|
+
| `staticFolder` | See [Static assets](#static-assets) |
|
|
170
|
+
| `apiPrefix` | See [REST URIs prefixes](#rest-uris-prefixes) |
|
|
171
|
+
| `cacheControl` | The `Cache-control` response header value for each GET request. |
|
|
172
|
+
| `delay` | After processing the request, the delay in milliseconds before the request should be sent. |
|
|
171
173
|
|
|
172
174
|
## Not supported (yet?)
|
|
173
175
|
|