diff --git a/.svrxrc.js b/.svrxrc.js new file mode 100644 index 0000000..44bfc4b --- /dev/null +++ b/.svrxrc.js @@ -0,0 +1,16 @@ +module.exports = { + port: 3000, + https: false, + // registry: 'https://registry.npm.taobao.org', + plugins: [ + { + name: 'qrcode', + options: { + ui: true + } + }, + // 'weinre', + 'mock', + + ] +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..e38feea --- /dev/null +++ b/README.md @@ -0,0 +1,57 @@ +# 插件模板 + +## 环境搭建 + +### 安装[svrx](https://docs.svrx.io/zh/quick-start.html) + +```bash +npm install -g @svrx/cli +``` + +### 运行 + +```bash +npm run dev +``` + +## mock + +修改route.js里的文件, 范例: +```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('haha'); +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}'); +``` + +参考文档: + ++ [route使用](https://docs.svrx.io/zh/guide/route.html) ++ [mock](https://docs.svrx.io/zh/blog/mock.html#%E4%BD%BF%E7%94%A8-mock-%E6%8F%92%E4%BB%B6%E6%9D%A5%E5%BF%AB%E9%80%9F%E6%A8%A1%E6%8B%9F%E6%8E%A5%E5%8F%A3) ++ [mock.js语法](http://mockjs.com/0.1/) + +## 开发注意事项 + ++ 请求推荐使用[fetch](https://developer.mozilla.org/zh-CN/docs/Web/API/Fetch_API) ++ 内置插件要求有唯一的根元素, 添加data-root属性, 以此来进行DOM操作,data-root的值, 会再插件绑定时动态替换为全局唯一的id. data-root属性在代码片段中, 只允许在根元素上出现 ++ TALL传递的数据从根元素的父级元素上通过data-[xxx]的方式获取 ++ 代码片段中不允许添加id等属性(TALL页面中会出现多个同样的插件) ++ 插件的script里要添加全局的命名空间, 命名格式为p[id], 如插件id为100, namespace为p100 diff --git a/package.json b/package.json new file mode 100644 index 0000000..c862448 --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "plugin-templete", + "version": "1.0.0", + "description": "", + "main": ".svrxrc.js", + "scripts": { + "dev": "svrx --mock --route route.js" + }, + "repository": { + "type": "git", + "url": "gitea@dd.tall.wiki:wally/plugin-templete.git" + }, + "keywords": [], + "author": "", + "license": "ISC" +} diff --git a/route.js b/route.js new file mode 100644 index 0000000..ccf7171 --- /dev/null +++ b/route.js @@ -0,0 +1,7 @@ +get('/blog').to.json({ + code: 200, + msg: 'ok', + data: { + title: 'Hello world' + } +}) diff --git a/刷新_好压看图.png b/刷新_好压看图.png deleted file mode 100644 index a1d7021..0000000 Binary files a/刷新_好压看图.png and /dev/null differ