whistle.interceptors 0.0.1 → 0.0.3
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/.console.log +2 -0
- package/dist/server.js +1 -1
- package/dist/uiServer/index.js +1 -0
- package/index.js +1 -0
- package/package.json +16 -4
- package/public/assets/index-Bn3cFRn4.css +1 -0
- package/public/assets/index-yFos5qg5.js +83 -0
- package/public/assets/vanilla-picker-B6E6ObS_.js +8 -0
- package/public/index.html +14 -0
- package/public/vite.svg +1 -0
- package/src/server.ts +166 -0
- package/src/types/base.d.ts +17 -0
- package/src/types/global.d.ts +378 -0
- package/src/types/rule.ts +13 -0
- package/src/uiServer/constant.ts +11 -0
- package/src/uiServer/index.ts +41 -0
- package/src/uiServer/router.ts +40 -0
- package/tsup.config.ts +11 -0
- package/README.md +0 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
declare module 'koa' {
|
|
2
|
+
interface DefaultContext {
|
|
3
|
+
storage: Whistle.Storage
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
import Koa from 'koa';
|
|
8
|
+
import bodyParser from 'koa-bodyparser';
|
|
9
|
+
// import onerror from 'koa-onerror';
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
import cors from '@koa/cors';
|
|
12
|
+
import serve from 'koa-static';
|
|
13
|
+
import path from 'path';
|
|
14
|
+
import Router from 'koa-router';
|
|
15
|
+
import setupRouter from './router';
|
|
16
|
+
|
|
17
|
+
const MAX_AGE = 1000 * 60 * 5;
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
export default (server: Whistle.PluginServer, options: Whistle.PluginOptions) => {
|
|
21
|
+
|
|
22
|
+
const app = new Koa();
|
|
23
|
+
|
|
24
|
+
app.context.storage = options.storage;
|
|
25
|
+
|
|
26
|
+
app.proxy = true;
|
|
27
|
+
app.silent = true;
|
|
28
|
+
app.use(
|
|
29
|
+
cors({
|
|
30
|
+
allowMethods: ['GET', 'POST', 'PUT', 'DELETE'],
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
// onerror(app);
|
|
34
|
+
const router = new Router();
|
|
35
|
+
setupRouter(router);
|
|
36
|
+
app.use(bodyParser());
|
|
37
|
+
app.use(router.routes());
|
|
38
|
+
app.use(router.allowedMethods());
|
|
39
|
+
app.use(serve(path.join(__dirname, '../../public'), { maxage: MAX_AGE }));
|
|
40
|
+
server.on('request', app.callback());
|
|
41
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import Router from 'koa-router';
|
|
2
|
+
import { apis, LOCAL_PREFIX } from './constant';
|
|
3
|
+
|
|
4
|
+
type RouterContext = {
|
|
5
|
+
storage: Whistle.Storage
|
|
6
|
+
} & Router.IRouterContext
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export default (router: Router) => {
|
|
10
|
+
|
|
11
|
+
router.get(apis.get, (ctx: RouterContext) => {
|
|
12
|
+
try {
|
|
13
|
+
const data = ctx.storage.getProperty(LOCAL_PREFIX);
|
|
14
|
+
console.log('get data', data)
|
|
15
|
+
ctx.body = {
|
|
16
|
+
result: 'ok',
|
|
17
|
+
data: JSON.parse(data)
|
|
18
|
+
}
|
|
19
|
+
} catch (error) {
|
|
20
|
+
ctx.body = {
|
|
21
|
+
result: 'error',
|
|
22
|
+
data: 'get rules error ' + error
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
router.post(apis.add, (ctx : RouterContext) => {
|
|
28
|
+
console.log('ssss', ctx.request.body, typeof ctx.request.body)
|
|
29
|
+
ctx.storage.setProperty(LOCAL_PREFIX, JSON.stringify(ctx.request.body))
|
|
30
|
+
ctx.body = {
|
|
31
|
+
result: 'ok',
|
|
32
|
+
data: null
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
router.delete(apis.delete, (ctx) => {
|
|
37
|
+
console.log('ssss', ctx)
|
|
38
|
+
ctx.body = 'ok'
|
|
39
|
+
});
|
|
40
|
+
};
|
package/tsup.config.ts
ADDED
package/README.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# whistle.interceptors
|