{"id":21559728,"url":"https://github.com/kaola-fed/jmockr","last_synced_at":"2026-05-20T09:10:30.166Z","repository":{"id":57281225,"uuid":"74583276","full_name":"kaola-fed/jMockr","owner":"kaola-fed","description":"Mock server for front end develop","archived":false,"fork":false,"pushed_at":"2018-03-29T13:40:37.000Z","size":514,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-16T17:51:21.683Z","etag":null,"topics":["express","mock-data","module","sync-data"],"latest_commit_sha":null,"homepage":"","language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kaola-fed.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-23T14:16:59.000Z","updated_at":"2018-06-20T07:47:37.000Z","dependencies_parsed_at":"2022-09-19T21:16:06.473Z","dependency_job_id":null,"html_url":"https://github.com/kaola-fed/jMockr","commit_stats":null,"previous_names":["yubaoquan/jmockr"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaola-fed%2FjMockr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaola-fed%2FjMockr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaola-fed%2FjMockr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaola-fed%2FjMockr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kaola-fed","download_url":"https://codeload.github.com/kaola-fed/jMockr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244155533,"owners_count":20407364,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["express","mock-data","module","sync-data"],"created_at":"2024-11-24T09:09:10.014Z","updated_at":"2026-05-20T09:10:30.134Z","avatar_url":"https://github.com/kaola-fed.png","language":"CSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jmockr introduction\n\n[中文文档](https://github.com/yubaoquan/jMockr/blob/master/readme.zh-CN.md)\n[![NPM version][npm-image]][npm-url]\n[![Build Status](https://travis-ci.org/kaola-fed/jMockr.svg?branch=master)](https://travis-ci.org/kaola-fed/jMockr)\n[![npm download][download-image]][download-url]\n\n[npm-image]: http://img.shields.io/npm/v/jmockr.svg?style=flat-square\n[npm-url]: http://npmjs.org/package/jmockr\n[download-image]: https://img.shields.io/npm/dm/jmockr.svg?style=flat-square\n[download-url]: https://npmjs.org/package/jmockr\n\nA `nodejs`, `expressjs` based mock server, currently support two server side templates: `freemarker` and `thymeleaf`. (The thymeleaf parsing relys on package [thymeleaf](https://www.npmjs.com/package/thymeleaf#), and this package is not fully developed. So the support of thymeleaf is kind of weak)\n\n## 0. Migrate from 1.x to 3.x\n\n```\nnpm run jmockr -m\n```\n## 1. Install\n\n\n[![dom-scroll-into-view](https://nodei.co/npm/jmockr.png)](https://npmjs.org/package/jmockr)\n\n`npm install jmockr`\n\n## 2. Config\n\nThe config file is named `jmockr.config.json`, located in the folder where jmockr in.(the folder where you run `npm install jmockr`)\n\n\nHere is a demo:\n\n ```\n{\n    \"authConfig\": {\n        \"username\": \"xxxxx\", //useless now\n        \"password\": \"xxxxx_\" //useless now\n    },\n    \"proxyConfig\": { // proxy config\n        \"enable\": true, // whether proxy the ajax request to other server\n        \"useIP\": false, // use IP to locate the target server, if set to true, the `domain` is omitted, otherwise `ip` is omitted\n        \"protocol\": \"https\",\n        \"domain\": \"xxx.yyy.com\",\n        \"ip\": \"127.0.0.1\",\n        \"enablePort\": false, // whether send request to a specific port of target server, if set to false, the `port` is omitted\n        \"port\": 4000\n    },\n    \"dataPath\": {\n        \"urlMap\": \"mock/urlMap.json\", // 1.[file]\n        \"commonSync\": \"mock/commonSyncData\", // 2.[folder]\n        \"commonAsync\": \"mock/commonAsync\", // 3.[folder]\n        \"pageSync\": \"mock/ftlMockData\", // 4.[folder]\n        \"pageAsync\": \"mock/ajax\" // 5.[folder]\n    },\n    \"serverConfig\": {\n        \"port\": 3000, // port jmockr listens on\n        \"static\": \"./webapp\", // static files are put here, like css or js files\n        \"noOpenPage\": false, // whether open the default page in browser. if initialURL is set, this option is omitted\n        \"initialURL\": 'www.test.com' // Default page to open after server launched. If ommited, will set to `http://localhost:port`\n    },\n    \"templateType\": \"freemarker\", // freemarker or thymeleaf\n    \"templateRoot\": \"xxxx\", // Folder\n    \"moduleFtlPathes\": [\"aaa\", \"bbb\"], // Folder\n    \"liveReload\": { // live reload config\n        \"watch\": [ // paths to watch, if file under these has changed, server will refresh the browser\n             \"**/*.css\",\n             \"**/*.js\",\n             \"**/*.html\",\n             \"**/*.ftl\"\n        ],\n        \"ignore\": [ //paths not watch\n             \"../ignore/**/*.*\"\n        ]\n    }\n}\n ```\n\n 1. Array of map, the map is pages url to page template file, like`[{\"entry\": \"/this/is/a/page\", \"template\": \"/the/template/file\"}, {\"entry\": \"xxxxx2\", \"template\": \"yyyyy2\"}]`. File suffix of templates like `.ftl`, `.html` should be omitted. Below is an example:\n\n```\n [{\"entry\": \"xxxx\", \"template\": \"/a/b.ftl\"}] // wrong\n [{\"entry\": \"xxxx\", \"template\": \"/a/b\"}] // right\n ```\n\n 2. A folder stores common freemarker mock data(the mock data that all pages need to use), files under the folder are json files.\n\n 3. A root folder stores common ajax config folders, each subfolder in root folder contains two file: one file (its name could be `url.js`, `url.json` or `url.json5`) contains the urls of the ajax, another file (its name could be `data.js`, `data.json` or `data.json5`) contains the response data of the urls, below is an example:\n ```\n // structure\n /mock/commonAsync/\n                |\n                -------api1\n                |        |\n                |        |--url.json\n                |        |--data.json\n                |\n                |------api2\n                |        |\n                |        |--url.json\n                |        |--data.json\n\n// url.json\n\n[\n    '/the/first/url.do',\n    '/the/second/url.do',\n    //...\n]\n\n// data.json\n\n{\n    someKey1: someVal1,\n    someKey2: someVal2,\n    //...\n}\n\n// All the ajax of url in url.json will response data in data.json which in the same folder of url.json.\n ```\n\n 4. Folder stores page scoped freemarker mock data ftl mock. Every file in this folder is json file, see\u003ca href=\"#mmgz\"\u003enaming rule\u003c/a\u003e\n\n 5. Each ajax mock data is put in a json file. All ajax mock data file are put in a page scoped ajax folder (to name this folder, see \u003ca href=\"#mmgz\"\u003enaming rule\u003c/a\u003e), all the folders is in this folder.\n\n 6. Store all ftl files or subfolders(ralative to jmockr config file).\n\n 7. Other ftl's root path(on the same level or out of `templateRoot`, for example ftl in node_modules)\n\n**Tips: all relative paths are relative to `jmockr.config.json`**\n\n\n\u003cdiv id=\"mmgz\"\u003eNaming rule\u003c/div\u003e\nTake a page who's url is `/abc/def.do` for instance,\n\n1. Remove the first slash in url\n2. Replace rest slashes in url to dot. so filename of sync data for the page is `abc.def.do.json`\n3. Under ajax mock data folder, all ajax config files have no limit of naming rule, but must be json file or exportable .js file, such as `1.json`, `abc.json` are valid.\n\nExample:\n\n#### a. Page route and sync mock data config\n\nWhen you create a page, like\n\n\u003e page url：/abc/def.do\n\n\u003e freemarker file location：new_template/pages/aaa/bbb/ccc.ftl\n\nYou need to add one config item to array in `mock/urlMap.json`\n\n    {\n        entry: '/abc/def.do',\n        template: 'new_template/pages/aaa/bbb/ccc.ftl'\n    }\nIf you need to put some sync data to freemarker, create a new file named`abc.def.do.json`, put it to `mock/ftlMockData/` fill the sync mock data in this file, like:\n\n    {\n        sentence: \"Hello World\",\n        sentence2: 'abcdefg',\n        arr: [1, 2, 3, 4, 5, 6, 7]\n    }\n\n#### b. Async mock data config\n\n##### 1.Complete config\n\nAdd `abc.def.do` to `mock_server/mock/ajax/`\n\nFile name is entry(the page url) exclude the first slash.\n\nWhen add an ajax config to the page，add a json file to `abc.def.do`, file name is not limited，data structure like this：\n\n    {\n        \"url\": \"/cms/album/searchTag.do\",   // the ajax url\n        \"method\": \"post\",                   // (get/post/put/delete) if omitted, set to post.\n        //if want to support multi methods to a ajax, split the methods with comma. like\"method\": \"get,post\"\n        \"result\": {                         // response data from ajax\n            \"abc\": \"def\"\n        }\n    }\n\n#### c.Proxy config\n\n异步数据除了在本地的json文件中配置外, 还可以直接调用测试环境的接口获取, 即代理功能.\n\n此功能的相关配置放在/config/proxy.json文件中, 将`enable`属性设置为true, 即可开启代理功能.\n\n代理功能支持两种方式配置转发地址: **ip:端口**和**域名**. 默认情况下使用域名模式. 将`enablePort`属性设置为true即开启ip:端口模式.\n\n测试环境的账号和口令配置放在/auth/config.json中, 可根据具体情况进行修改.\n\n**如果开启代理, 请确认当前host或者ip是自己需要调试的目标地址, 避免产生环境不对造成接口访问不到的问题**\n\n## 3. Start up command\n\n    `jmockr -n` or `jmockr --normal` normal start, modifying mock data or page code will not trigger restart\n    `jmockr -s` or `jmockr --start` hot start, modifying mock data will trigger server to reload routes and mock data\n    `jmockr -l` or `jmockr --live` hot start with live reload, modifying page code such as js /css /html will trigger browser to reload the page\n\n## 4.tips\n\n1. jmockr support json5 file and json5 style in json file, like below:\n\n```\n{\n    foo: 'bar',\n    while: true,\n\n    this: 'is a \\\nmulti-line string',\n\n    // this is an inline comment\n    here: 'is another', // inline comment\n\n    /* this is a block comment\n       that continues on another line */\n\n    hex: 0xDEADbeef,\n    half: .5,\n    delta: +10,\n    to: Infinity,   // and beyond!\n\n    finally: 'a trailing comma',\n    oh: [\n        \"we shouldn't forget\",\n        'arrays can have',\n        'trailing commas too',\n    ],\n}\n```\n\n\n More about [JSON5](https://github.com/json5/json5)\n\n## License\n\njMockr is released under the ISC license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaola-fed%2Fjmockr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkaola-fed%2Fjmockr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaola-fed%2Fjmockr/lists"}