@makano/rew 1.2.86 → 1.2.87
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/rew/pkgs/serve.js +17 -0
- package/package.json +1 -1
package/lib/rew/pkgs/serve.js
CHANGED
@@ -6,6 +6,7 @@ const { run } = require('../main');
|
|
6
6
|
const { runPath } = require('../modules/runtime');
|
7
7
|
const { cleanCache } = require('../functions/import');
|
8
8
|
const { REW_FILE_TYPE } = require('../const/ext');
|
9
|
+
const { Usage } = require('../const/usage');
|
9
10
|
|
10
11
|
const lookUpFiles = ['route', 'page', 'page.s'];
|
11
12
|
|
@@ -85,6 +86,17 @@ module.exports = (context) => {
|
|
85
86
|
return this;
|
86
87
|
}
|
87
88
|
|
89
|
+
onFetch(fn, override = false){
|
90
|
+
if(this.options.fetch && !override){
|
91
|
+
const originalFn = fn;
|
92
|
+
fn = (...args) => {
|
93
|
+
return originalFn(...args, this.options.fetch(...args));
|
94
|
+
}
|
95
|
+
}
|
96
|
+
this.options.fetch = fn;
|
97
|
+
return this;
|
98
|
+
}
|
99
|
+
|
88
100
|
port(port){
|
89
101
|
this.listen = port;
|
90
102
|
return this;
|
@@ -301,6 +313,11 @@ module.exports = (context) => {
|
|
301
313
|
return new Server(options);
|
302
314
|
}
|
303
315
|
|
316
|
+
service = Usage.prototype.create('svr.service', (cb) => {
|
317
|
+
const server = Svr.prototype.create();
|
318
|
+
cb(server);
|
319
|
+
});
|
320
|
+
|
304
321
|
router({ id = '/', type = 'normal', ...options }){
|
305
322
|
let router;
|
306
323
|
if(type == 'default') router = SvrRouter.new(IttyRouter, {...options}, { id });
|