{"id":13989609,"url":"https://github.com/flftfqwxf/mockserver","last_synced_at":"2025-04-05T06:10:46.792Z","repository":{"id":12626216,"uuid":"67780262","full_name":"flftfqwxf/mockserver","owner":"flftfqwxf","description":"Mockserver is a  mock data tools and switch between mock data and real data,【一个用于前后分离时模拟数据的web系统，并可在直实数据与实际数据中自由切换】","archived":false,"fork":false,"pushed_at":"2022-02-12T07:27:43.000Z","size":14383,"stargazers_count":337,"open_issues_count":3,"forks_count":103,"subscribers_count":33,"default_branch":"master","last_synced_at":"2024-04-29T21:49:15.786Z","etag":null,"topics":["api-test","data-mock","mock-server","nodejs","postman"],"latest_commit_sha":null,"homepage":"http://mock.chinesefoodrecipes.net","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flftfqwxf.png","metadata":{"files":{"readme":"README-EN.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-09-09T08:17:19.000Z","updated_at":"2024-04-29T21:49:15.787Z","dependencies_parsed_at":"2022-08-07T07:00:28.623Z","dependency_job_id":null,"html_url":"https://github.com/flftfqwxf/mockserver","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flftfqwxf%2Fmockserver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flftfqwxf%2Fmockserver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flftfqwxf%2Fmockserver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flftfqwxf%2Fmockserver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flftfqwxf","download_url":"https://codeload.github.com/flftfqwxf/mockserver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247294541,"owners_count":20915340,"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":["api-test","data-mock","mock-server","nodejs","postman"],"created_at":"2024-08-09T13:01:50.727Z","updated_at":"2025-04-05T06:10:46.771Z","avatar_url":"https://github.com/flftfqwxf.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"Mock-server is a Node.js web system for mock data,and switch between mock data and real data.\n\n[中文文档](README.md)\n\n## Features\n\n \n  \n  - Supports  [jsonEditor](http://jsoneditoronline.org/) \n \n  - Supports method types: GET、POST、PUT、DELETE...\n\n  - RESTful path format，e.g: /a/:user/:id\n \n  - Allow to specify status code，default:200\n \n  - Supports delay to return data\n \n  - Supports [Mockjs](http://mockjs.com/)\n\n  - Supports json for cross-domain calls  \n\n  - Supports switch between mock data and real data\n \n  - Supports switch between Chinese and English\n  \n  - Support 'text/plain' type post \n  \n\n\n## [demo](http://47.93.62.181:8033/)\n\n### This demo is for demonstration purposes only.The System will clear data regularly\n\n\n\n## Install dependencies\n\n```\nnpm install\n```\n## Initialize database\n\n1. Use MockServer automatic initialization feature (recommend)\n2. Manually import .sql file\n\n```\nmysql[5.7.14]+,\nimport mysql file [mockserver-xx-xx.sql]\nmysql coifnig in [/src/common/config/db.js]\n```\n\n## Config \n``\n/src/common/config/config.js\n``\n\n## Start server\n\n```\nnpm start\n#Server running at http://127.0.0.1:8033/\n\n```\n\n\n## Examples\n\n### Suppose:\n\n- Mock Server running at http://127.0.0.1:8033\n- Created a project，project id：8a15fbb94471050bb46f\n\n- Created a API :  /api/demo\n\n### cross-domain:\n\n**With the jQuery AJAX methods:**\n\n```\n    $.getJSON('http://127.0.0.1:8033/8a15fbb94471050bb46f/api/demo').done(function(){\n    \n    \n    }).fail(function(){\n    \n    })\n\n```\n\n### Same domain and mock-server proxy URL different with nginx server_name：\n\n### Suppose:\n\n- Mock Server running at http://127.0.0.1:8033\n- Created a project，project id：8a15fbb94471050bb46f\n\n- Created a API :  /api/demo\n\n**nginx config:**\n\n```\n        server {\n            listen 80;\n            server_name your.site.com;\n            root your/project/path;\n    \n            gzip_static on;\n    \n            # proxy to mock server\n            location ^~ /api {\n                rewrite ^/api/(.*) '/8a15fbb94471050bb46f/api/$1' break;\n                 proxy_set_header Host $host;\n                 proxy_set_header X-Real-IP $remote_addr;\n                 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n                 proxy_set_header X-Forwarded-Proto $scheme;\n                 proxy_pass http://127.0.0.1:8033/;\n                 break;\n            }\n           \n    \n            # Attempt to load static files, if not found route to @rootfiles\n            location ~ (.+)\\.(html|json|txt|js|css|jpg|jpeg|gif|png|svg|ico|eot|otf|woff|woff2|ttf)$ {\n                add_header Access-Control-Allow-Origin *;\n    \n                try_files $uri @rootfiles;\n            }\n    \n            # Check for app route \"directories\" in the request uri and strip \"directories\"\n            # from request, loading paths relative to root.\n            location @rootfiles {\n                rewrite ^/(?:foo/bar/baz|foo/bar|foo|tacos)/(.*) /$1 redirect;\n            }\n        }\n\n```\n\n\n### Same domain and mock-server proxy URL equals nginx server_name：\n\n### Suppose:\n\n- Your Web Server running at http://127.0.0.1:8034\n- Mock Server running at http://127.0.0.1:8033\n- Created a API :  /api/demo\n- Created a project，project id：8a15fbb94471050bb46f\n- Proxy URL value : http://www.site.com\n- Nginx server_name : www.site.com\n\n**nginx config:**\n\n```\n        server {\n                   listen 80;\n                   server_name  www.site.com;\n                   root your/project/path;\n                   gzip_static on;\n                    \n                   location ^~ /api {\n                       set $is_proxy 0;\n                       # $http_is_mock_server_proxy comes from mock-server when mock-server's proxy is opened\n                       if ($http_is_mock_server_proxy){\n                           # $http_is_mock_server_proxy is mock-server writed header\n                           set $is_proxy $http_is_mock_server_proxy;\n               \n                       }\n                       # $is_proxy\n                       # nginx proxy to mock-server\n                       if ($is_proxy = 0 ){\n                             rewrite ^/api/(.*) '/8a15fbb94471050bb46f/api/$1' break;\n                             proxy_set_header Host $host;\n                             proxy_set_header X-Real-IP $remote_addr;\n                             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n                             proxy_set_header X-Forwarded-Proto $scheme;\n                             proxy_pass http://127.0.0.1:8033/;\n                             break;\n                       }\n               \n                       #Avoid circular proxy\n                       if ($is_proxy = 1 ){\n                           add_header http_is_mock_server_proxy \"$is_proxy\";\n                           proxy_pass http://127.0.0.1:8034;\n                           break;\n               \n                       }\n                   }\n                   location  / {\n                       proxy_pass http://127.0.0.1:8034;\n                   }\n               \n               }\n```\n\n **Ajax in your.site.com:**\n\n```\n    $.getJSON('/api/demo').done(function(){\n    \n    \n    }).fail(function(){\n    \n    })\n\n```\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflftfqwxf%2Fmockserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflftfqwxf%2Fmockserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflftfqwxf%2Fmockserver/lists"}