{"id":19847827,"url":"https://github.com/mascrypt0/lite-weight-server","last_synced_at":"2025-10-24T02:31:40.728Z","repository":{"id":227404319,"uuid":"771329432","full_name":"mascrypt0/lite-weight-server","owner":"mascrypt0","description":"Lightweight node server for web app","archived":false,"fork":false,"pushed_at":"2024-03-13T06:52:26.000Z","size":49,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-11T22:32:49.703Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/mascrypt0.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":"2024-03-13T05:13:06.000Z","updated_at":"2024-03-13T06:51:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"7c3d3cd7-3e9f-4031-8b88-1d90ccb7d4a0","html_url":"https://github.com/mascrypt0/lite-weight-server","commit_stats":null,"previous_names":["mascrypt0/lite-weight-server"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mascrypt0%2Flite-weight-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mascrypt0%2Flite-weight-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mascrypt0%2Flite-weight-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mascrypt0%2Flite-weight-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mascrypt0","download_url":"https://codeload.github.com/mascrypt0/lite-weight-server/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241226809,"owners_count":19930487,"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":[],"created_at":"2024-11-12T13:15:19.620Z","updated_at":"2025-10-15T21:36:24.661Z","avatar_url":"https://github.com/mascrypt0.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lite-weight-server\n\nBrowserSync does most of what we want in a super fast lightweight development server. It serves the static content, detects changes, refreshes the browser, and offers many customizations.\n\nWhen creating a SPA there are routes that are only known to the browser. For example, `/customer/21` may be a client side route for an Angular app. If this route is entered manually or linked to directly as the entry point of the Angular app (aka a deep link) the static server will receive the request, because Angular is not loaded yet. The server will not find a match for the route and thus return a 404. The desired behavior in this case is to return the `index.html` (or whatever starting page of the app we have defined). BrowserSync does not automatically allow for a fallback page. But it does allow for custom middleware. This is where `lite-weight-server` steps in.\n\n`lite-weight-server` is a simple customized wrapper around BrowserSync to make it easy to serve SPAs.\n\n## Installation and Usage\n\nThe recommended installation method is a local NPM install for your project:\n\n```bash\nnpm install lite-weight-server --save-dev\nyarn add lite-weight-server --dev # or yarn\n```\n\n...and add a \"script\" entry within your project's `package.json` file:\n\n```json\n# Inside package.json...\n  \"scripts\": {\n    \"dev\": \"lite-weight-server\"\n  },\n```\n\nWith the above script entry, you can then start `lite-weight-server` via:\n\n```bash\nnpm run dev\n```\n\nOther options for running locally installed NPM binaries is discussed in this Stack Overflow question: [How to use package installed locally in node_modules](http://stackoverflow.com/q/9679932)\n\n### Using on the fly\n\nlite-weight-server can be used with `npx`\n\n```bash\nnpx lite-weight-server\n```\n\n### Global Installation\n\nlite-weight-server can be also installed globally, if preferred:\n\n```bash\nnpm install --global lite-weight-server\n\n# To run:\nlite-weight-server\n```\n\n## Custom Configuration\n\nThe default behavior serves from the current folder, opens a browser, and applies a HTML5 route fallback to `./index.html`.\n\nlite-weight-server uses [BrowserSync](https://www.browsersync.io/), and allows for configuration overrides via a local `bs-config.json` or `bs-config.js` file in your project.\n\nYou can provide custom path to your config file via `-c` or `--config=` run time options:\n\n```bash\nlite-weight-server -c configs/my-bs-config.js\n```\n\nFor example, to change the server port, watched file paths, and base directory for your project, create a `bs-config.json` in your project's folder:\n\n```json\n{\n  \"port\": 8000,\n  \"files\": [\"./src/**/*.{html,htm,css,js}\"],\n  \"server\": { \"baseDir\": \"./src\" }\n}\n```\n\nYou can also provide custom path to your base directory `--baseDir=` run time options:\n\n```bash\nlite-weight-server --baseDir=\"dist\"\n```\n\nA more complicated example with modifications to the server middleware can be done with a `bs-config.js` file, which requires the `module.exports = { ... };` syntax:\n\n```js\nmodule.exports = {\n  server: {\n    middleware: {\n      // overrides the second middleware default with new settings\n      1: require('connect-history-api-fallback')({\n        index: '/index.html',\n        verbose: true,\n      }),\n    },\n  },\n};\n```\n\nThe `bs-config.js` file may also export a function that receives the lite-server Browsersync instance as its only argument. While not required, the return value of this function will be used to extend the default lite-server configuration.\n\n```js\nmodule.exports = function (bs) {\n  return {\n    server: {\n      middleware: {\n        // overrides the second middleware default with new settings\n        1: require('connect-history-api-fallback')({\n          index: '/index.html',\n          verbose: true,\n        }),\n      },\n    },\n  };\n};\n```\n\n**NOTE:** Keep in mind that when using middleware overrides the specific middleware module must be installed in your project. For the above example, you'll need to do:\n\n```bash\nnpm install connect-history-api-fallback --save-dev\n```\n\n...otherwise you'll get an error similar to:\n\n```bash\nError: Cannot find module 'connect-history-api-fallback'\n```\n\nAnother example: To remove one of the [default middlewares](./lib/config-defaults.js), such as `connect-logger`, you can set it's array index to `null`:\n\n```js\nmodule.exports = {\n  server: {\n    middleware: {\n      0: null, // removes default `connect-logger` middleware\n    },\n  },\n};\n```\n\nA list of the entire set of BrowserSync options can be found in its docs: \u003chttp://www.browsersync.io/docs/options/\u003e\n\n## Testing\n\nWhen using `lite-server` to run end to end tests, we may not want to log verbosely. We may also want to prevent the browser from opening. These options in the `bs-config.js` will silence all logging from `lite-weight-server`:\n\n```js\n  open: false\n  logLevel: \"silent\",\n  server: {\n    middleware: {\n      0: null\n    }\n  }\n```\n\n## Known Issues\n\nCSS with Angular 2 is embedded thus even though BrowserSync detects the file change to CSS, it does not inject the file via sockets. As a workaround, `injectChanges` defaults to `false`.\n\n## Contributing\n\n1. Fork and clone it\n1. Install dependencies: `npm install`\n1. Create a feature branch: `git checkout -b new-feature`\n1. Commit changes: `git commit -am 'Added a feature'`\n1. Run static code analysis and unit tests: `npm test`\n1. Push to the remote branch: `git push origin new-feature`\n1. Create a new Pull Request\n\n## License\n\nCode released under the [MIT license](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmascrypt0%2Flite-weight-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmascrypt0%2Flite-weight-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmascrypt0%2Flite-weight-server/lists"}