{"id":13403905,"url":"https://github.com/lukejacksonn/servor","last_synced_at":"2025-05-15T01:08:57.365Z","repository":{"id":37752332,"uuid":"74576329","full_name":"lukejacksonn/servor","owner":"lukejacksonn","description":"Dependency free file server for single page app development","archived":false,"fork":false,"pushed_at":"2023-03-09T17:17:04.000Z","size":123,"stargazers_count":1054,"open_issues_count":25,"forks_count":70,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-05-13T17:22:45.507Z","etag":null,"topics":["development","file-watcher","history-api-fallback","live-reload","server","single-page-app"],"latest_commit_sha":null,"homepage":"","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/lukejacksonn.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-23T12:49:31.000Z","updated_at":"2025-05-09T16:22:29.000Z","dependencies_parsed_at":"2024-06-18T12:30:21.456Z","dependency_job_id":"d8f67502-89e2-425f-8df5-170578cba66b","html_url":"https://github.com/lukejacksonn/servor","commit_stats":{"total_commits":103,"total_committers":13,"mean_commits":7.923076923076923,"dds":"0.12621359223300976","last_synced_commit":"ec7d824ea6903c0fb97a452045bbb8335198cbab"},"previous_names":["lukejacksonn/http-server-spa"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukejacksonn%2Fservor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukejacksonn%2Fservor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukejacksonn%2Fservor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukejacksonn%2Fservor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukejacksonn","download_url":"https://codeload.github.com/lukejacksonn/servor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254004583,"owners_count":21998082,"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":["development","file-watcher","history-api-fallback","live-reload","server","single-page-app"],"created_at":"2024-07-30T19:01:36.138Z","updated_at":"2025-05-15T01:08:52.358Z","avatar_url":"https://github.com/lukejacksonn.png","language":"JavaScript","readme":"# Servør\n\n\u003e A dependency free dev server for modern web application development\n\nA very compact but capable static file server with https, live reloading, gzip and other useful features to support modern web app development on localhost and over a local network. The motivation here was to write a package from the ground up with no dependencies; using only native, node and browser APIs to do some specific tasks with minimal code.\n\nServør can be invoked via the command line or programmatically using the node API.\n\n**Quickstart Example**\n\nThe following command instructs servør to; clone [perflink](https://github.com/lukejacksonn/perflink), start a server at the project root, open the url in a browser, open the source code in an editor and reload the browser when files change.\n\n```s\nnpx servor gh:lukejacksonn/perflink --browse --editor --reload\n```\n\nMost features are disabled by default but you can customize behaviour by passing positional arguments and flags to enable features.\n\n\u003chr\u003e\n\n\u003cimg src=\"https://user-images.githubusercontent.com/1457604/68399629-979e8480-016e-11ea-89b3-0f852a018042.gif\" alt=\"servor\" width=\"800\"\u003e\n\n## Features\n\n- 🗂 Serves static content like scripts, styles, images from a given directory\n- ♻️ Reloads the browser when project files get added, removed or modified\n- 🗜 Uses gzip on common filetypes like html, css, js and json\n- 🔐 Supports https and http2 with trusted self signed certificates\n- 🖥 Redirects all path requests to a single file for frontend routing\n- 📦 Accepts both HTML and JavaScript files as the root file for a directory\n- 🔎 Discovers freely available ports to start if the default is in use\n- 📄 Renders directory listing for urls ending with a trailing slash\n- 🗃 Opens browser tab and code editor to streamline quick start\n\n## CLI Usage\n\nRun as a terminal command without adding it as a dependency using `npx`:\n\n```s\nnpx servor \u003croot\u003e \u003cfallback\u003e \u003cport\u003e\n```\n\n\u003e You can pass a GitHub repo as `\u003croot\u003e` using the syntax `gh:\u003cuser\u003e/\u003crepository\u003e`\n\n- `\u003croot\u003e` path to serve static files from (defaults to current directory `.`)\n- `\u003cfallback\u003e` the file served for all non-file requests (defaults to `index.html`)\n- `\u003cport\u003e` what port you want to serve the files from (defaults to `8080`)\n\nOptional flags passed as non-positional arguments:\n\n- `--browse` causes the browser to open when the server starts\n- `--reload` causes the browser to reload when files change\n- `--secure` starts the server with https using generated credentials\n- `--silent` prevents the server node process from logging to stdout\n- `--module` causes the server to wrap the root in script type module tags\n- `--static` causes the server to route nested index files if they exist\n- `--editor` opens a code editor (currently only vscode) at the project root\n\nExample usage with npm scripts in a `package.json` file after running `npm i servor -D`:\n\n```json\n{\n  \"devDependencies\": {\n    \"servor\": \"4.0.0\"\n  },\n  \"scripts\": {\n    \"start\": \"servor www index.html 8080 --reload --browse\"\n  }\n}\n```\n\n### Generating Credentials\n\n\u003e NOTE: This process depends on the `openssl` command existing (tested on macOS and linux only)\n\nThe files `servor.crt` and `servor.key` need to exist for the server to start using https. If the files do not exist when the `--secure` flag is passed, then [`certify.sh`](/certify.sh) is invoked which:\n\n- Creates a local certificate authority used to generate self signed SSL certificates\n- Runs the appropriate `openssl` commands to produce:\n  - a root certificate (pem) so the system will trust the self signed certificate\n  - a public certificate (crt) that the server sends to clients\n  - a private key for the certificate (key) to encrypt and decrypt traffic\n\n#### Adding credentials to the trusted store\n\n\u003e NOTE: This process depends on the `sudo` and `security` commands existing (tested on macOS only)\n\nFor the browser to trust self signed certificates the root certificate must be added to the system trusted store. This can be done automatically by running `sudo servor --secure` which:\n\n- Adds the root certificate to the system Keychain Access\n- Prevents the \"⚠️ Your connection is not private\" screen\n- Makes the 🔒 icon appear in the browsers address bar\n\nThe approach was adopted from [@kingkool68/generate-ssl-certs-for-local-development](https://github.com/kingkool68/generate-ssl-certs-for-local-development)\n\n## API Usage\n\nUse servor programmatically with node by requiring it as a module in your script:\n\n```js\nconst servor = require('servor');\nconst instance = await servor({\n  root: '.',\n  fallback: 'index.html',\n  module: false,\n  static: false,\n  reload: false,\n  inject: ''\n  credentials: null,\n  port: 8080,\n});\n```\n\nThe `servor` function accepts a config object with optional props assigned the above default values if none are provided. Calling the `servor` function starts up a new server and returns an object describing its configuration.\n\n```js\nconst { url, root, protocol, port, ips } = await servor(config);\n```\n\n### Inject\n\nThe `inject` property accepts a string that gets appended to the servers root document (which is `index.html` by default). This could be used to inject config or extend the development servers behavior and capabilities to suit specific environments.\n\n```js\nconst config = require('package.json');\nservor({ inject: `\u003cscript\u003ewindow.pkg=${config}\u003c/script\u003e` });\n```\n\n### Credentials\n\nThe `credentials` property accepts an object containing the entries `cert` and `key` which must both be valid for the server to start successfully. If valid credentials are provided then the server will start serving over https.\n\nIt is possible to generate the appropriate credentials using the `--secure` CLI flag.\n\n## Notes\n\nThanks to all the contributors to this projects so far. If you find a bug please create an issue or if you have an idea for a new feature then fork the project and create a pull request. Let me know how you are using servør [on twitter](https://twitter.com/lukejacksonn).\n","funding_links":[],"categories":["JavaScript","工程"],"sub_categories":["redux 扩展","macros"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukejacksonn%2Fservor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukejacksonn%2Fservor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukejacksonn%2Fservor/lists"}