You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
4 years ago | |
---|---|---|
.gitignore | 4 years ago | |
.svrxrc.js | 4 years ago | |
README.md | 4 years ago | |
index.html | 4 years ago | |
package.json | 4 years ago | |
route.js | 4 years ago |
README.md
插件模板
环境搭建
安装svrx
npm install -g @svrx/cli
运行
npm run dev
mock
修改route.js里的文件, 范例:
get('/handle(.*)').to.handle((ctx) => { ctx.body = 'handle'; });
get('/blog(.*)').to.json({ code: 200 });
get('/code(.*)').to.send('code', 201);
get('/json(.*)').to.send({ json: true });
get('/text(.*)').to.send('haha');
get('/html(.*)').to.send('<html>haha</html>');
get('/rewrite:path(.*)').to.rewrite('/query{path}');
get('/redirect:path(.*)').to.redirect('localhost:9002/proxy{path}');
get('/api(.*)').to.proxy('http://mock.server.com/')
get('/test(.*)').to.proxy('http://mock.server.com/', {
secure: false,
})
get('/test/:id').to.proxy('http://{id}.dynamic.server.com/')
get('/query(.*)').to.handle((ctx) => {
ctx.body = ctx.query;
});
get('/header(.*)')
.to.header({ 'X-From': 'svrx' })
.json({ user: 'svrx' });
get('/user').to.json({ user: 'svrx' });
get('/sendFile/:path(.*)').to.sendFile('./{path}');
参考文档:
开发注意事项
- 请求推荐使用fetch
- 内置插件要求有唯一的根元素, 添加data-root属性, 以此来进行DOM操作,data-root的值, 会再插件绑定时动态替换为全局唯一的id. data-root属性在代码片段中, 只允许在根元素上出现
- TALL传递的数据从根元素的父级元素上通过data-[xxx]的方式获取
- 代码片段中不允许添加id等属性(TALL页面中会出现多个同样的插件)
- 插件的script里要添加全局的命名空间, 命名格式为p[id], 如插件id为100, namespace为p100
- js获取根元素, 通过data-root='xxx', 其余元素通过根元素进行获取, 保证插入TALL后获取到的元素是正确的