{"id":20698793,"url":"https://github.com/rwson/server-static","last_synced_at":"2026-03-03T16:41:35.011Z","repository":{"id":56345590,"uuid":"81521182","full_name":"rwson/server-static","owner":"rwson","description":"静态文件服务器，类似于live-server，支持自定义ajax请求路径mock数据","archived":false,"fork":false,"pushed_at":"2020-11-13T05:21:19.000Z","size":29,"stargazers_count":2,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-13T08:56:02.480Z","etag":null,"topics":["live-reload","mock-data","nodejs","static-server"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rwson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-10T03:13:33.000Z","updated_at":"2020-11-13T05:21:22.000Z","dependencies_parsed_at":"2022-08-15T17:00:53.136Z","dependency_job_id":null,"html_url":"https://github.com/rwson/server-static","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwson%2Fserver-static","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwson%2Fserver-static/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwson%2Fserver-static/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwson%2Fserver-static/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rwson","download_url":"https://codeload.github.com/rwson/server-static/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250331047,"owners_count":21413092,"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":["live-reload","mock-data","nodejs","static-server"],"created_at":"2024-11-17T00:26:53.244Z","updated_at":"2026-03-03T16:41:29.984Z","avatar_url":"https://github.com/rwson.png","language":"JavaScript","readme":"# static-server\n\n静态文件服务器,支持SPA,类似于[live-server](https://github.com/tapio/live-server),支持自定义ajax请求路径mock数据,支持模拟ajax跨域请求进行接口调试\n\n### 安装\n\n```bash\nnpm install server-static -g\n```\n安装完成\n\n可通过\n\n```bash\nstatic-server --help 或者 static-server -h\n```\n命令查看配置帮助文档\n\n\n\n可通过\n\n```bash\nstatic-server --port=3001 或者 static-server -p=3001\n```\n\n通过指定监听端口\n\n\n\n可通过\n\n```bash\nstatic-server --slient 或者 static-server -s\n```\n\n指定不监听文件\n\n\n\n可通过\n\n```bash\nstatic-server --dir=xxxxx 或者 static-server -d=xxxx\n```\n\n指定在哪个目录下启动服务\n\n\n\n也可以通过\n\n```bash\nstatic-server\n```\n\n的方式（读取默认配置）启动本服务\n\n\n### 配置(如不指定,就用默认配置)\n\n可以通过在项目根目录下新建名为`static-server.config.js`的文件进行配置\n\n\n\n\n```javascript\n//  static-server.config.js\n\nmodule.exports = {\n\tport: 4000,                         // 监听端口,默认3000,当端口被占用时随机\n\tentry: \"index.html\",                // 首页文件,及当路径为\"/\"时响应的页面 \n    target: \"http://localhost:8080\",    // 调试ajax接口的真实地址和前缀\n  \tslient: true,\t\t\t\t      //  是否监听文件\n\tignores: [                          //  忽略过滤器(可传入单个函数或者由函数组成的数组)\n\t\tfunction(file) {\n\t\t    return /node_modules/.test(file);\n\t\t}\n\t],\n\trouters: [                          //  自定义请求路由\n\t    {\n\t        url: \"/login\",              //  请求的真实地址\n\t        method: \"GET\",\n\t        cross: true                 //  是否跨域请求\n\t    },\n\t\t{\n\t\t\turl: \"/main\",                       //  路由\n\t\t\tmethod: \"GET\",                      //  请求方式\n\t\t\thandler: function(req, res, next) { //  改路由的处理函数(与connect模块调用方法一致)\n\t\t\t\tconsole.log(\"请求进来了\");\n\t\t\t\tres.statusCode = 200;\n\t\t\t\tres.end(JSON.stringify({\n\t\t\t\t\tres: \"test main\"\n\t\t\t\t}));\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\turl: \"/main2\",\n\t\t\tmethod: \"POST\",\n\t\t\thandler: function(req, res, next) {\n\t\t\t\tconsole.log(req.body);\n\t\t\t\tres.statusCode = 200;\n\t\t\t\tres.end(JSON.stringify({\n\t\t\t\t\ttip: \"请求内容\",\n\t\t\t\t\tres: req.body\n\t\t\t\t}));\n\t\t\t}\n\t\t}\n\t]\n};\n```\n\n在所有接口都需要跨域请求时,可以将`static-server.config.js`中的routers指定成一个对象，为如下结构即可支持全部接口跨域调试\n\n```javascript\n//  static-server.config.js\nmodule.exports = {\n\t//\t...\n    routers: {\n        url: \"*\",\n        method: \"*\",\n        cross: true\n    }\n\t//\t...\n};\n\n\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frwson%2Fserver-static","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frwson%2Fserver-static","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frwson%2Fserver-static/lists"}