{"id":13602519,"url":"https://github.com/sindresorhus/electron-serve","last_synced_at":"2025-05-15T18:09:02.334Z","repository":{"id":54939959,"uuid":"117075519","full_name":"sindresorhus/electron-serve","owner":"sindresorhus","description":"Static file serving for Electron apps","archived":false,"fork":false,"pushed_at":"2024-09-17T06:49:17.000Z","size":48,"stargazers_count":457,"open_issues_count":13,"forks_count":34,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-05-07T16:32:11.219Z","etag":null,"topics":["electron","electron-module","nodejs","npm-package","serve","server","single-page-app","static-file-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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"funding":{"github":"sindresorhus","open_collective":"sindresorhus","buy_me_a_coffee":"sindresorhus","custom":"https://sindresorhus.com/donate"},"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":"2018-01-11T09:00:55.000Z","updated_at":"2025-05-02T10:32:27.000Z","dependencies_parsed_at":"2023-12-21T05:36:38.402Z","dependency_job_id":"0f2ff519-2bbe-480a-a968-bd7733d35740","html_url":"https://github.com/sindresorhus/electron-serve","commit_stats":{"total_commits":38,"total_committers":12,"mean_commits":"3.1666666666666665","dds":"0.39473684210526316","last_synced_commit":"b845c841947947553221569c974eb0f9d99a7c54"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Felectron-serve","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Felectron-serve/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Felectron-serve/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Felectron-serve/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/electron-serve/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253661273,"owners_count":21943904,"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":["electron","electron-module","nodejs","npm-package","serve","server","single-page-app","static-file-server"],"created_at":"2024-08-01T18:01:26.153Z","updated_at":"2025-05-15T18:09:02.277Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://buymeacoffee.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["JavaScript","Tools","Library"],"sub_categories":["For Electron","Uncategorized"],"readme":"# electron-serve\n\n\u003e Static file serving for Electron apps\n\nNormally you would just use `win.loadURL('file://…')`, but that doesn't work when you're making a single-page web app, which most Electron apps are today, as [`history.pushState()`](https://developer.mozilla.org/en-US/docs/Web/API/History_API)'ed URLs don't exist on disk. It serves files if they exist, and falls back to `index.html` if not, which means you can use router modules like [`react-router`](https://github.com/ReactTraining/react-router), [`vue-router`](https://github.com/vuejs/vue-router), etc.\n\n## Install\n\n```sh\nnpm install electron-serve\n```\n\n*Requires Electron 30 or later.*\n\n## Usage\n\n```js\nimport {app, BrowserWindow} from 'electron';\nimport serve from 'electron-serve';\n\nconst loadURL = serve({directory: 'renderer'});\n\nlet mainWindow;\n\n(async () =\u003e {\n\tawait app.whenReady();\n\n\tmainWindow = new BrowserWindow();\n\n\tawait loadURL(mainWindow);\n\n\t// Or optionally with search parameters.\n\tawait loadURL(mainWindow, {id: 4, foo: 'bar'});\n\n\t// The above is equivalent to this:\n\tawait mainWindow.loadURL('app://-');\n\t// The `-` is just the required hostname\n})();\n```\n\n## API\n\n### loadUrl = serve(options)\n\n#### options\n\nType: `object`\n\n##### directory\n\n*Required*\\\nType: `string`\n\nThe directory to serve, relative to the app root directory.\n\n##### scheme\n\nType: `string`\\\nDefault: `'app'`\n\nCustom scheme. For example, `foo` results in your `directory` being available at `foo://-`.\n\n##### hostname\n\nType: `string`\\\nDefault: `'-'`\n\nCustom hostname.\n\n##### file\n\nType: `string`\\\nDefault: `'index'`\n\nCustom HTML filename. This gets appended with `'.html'`.\n\n##### isCorsEnabled\n\nType: `boolean`\\\nDefault: `true`\n\nWhether [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) should be enabled.\nUseful for testing purposes.\n\n##### partition\n\nType: `string`\\\nDefault: [`electron.session.defaultSession`](https://electronjs.org/docs/api/session#sessiondefaultsession)\n\nThe [partition](https://electronjs.org/docs/api/session#sessionfrompartitionpartition-options) where the protocol should be installed, if not using Electron's default partition.\n\n### loadUrl(window, searchParameters?)\n\nThe `serve` function returns a `loadUrl` function, which you use to serve your HTML file in that window.\n\n##### window\n\n*Required*\\\nType: `BrowserWindow`\n\nThe window to load the file in.\n\n##### searchParameters\n\nType: `object | URLSearchParams`\n\nKey value pairs or an [`URLSearchParams` instance](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) to set as the search parameters.\n\n## Related\n\n- [electron-util](https://github.com/sindresorhus/electron-util) - Useful utilities for developing Electron apps and modules\n- [electron-reloader](https://github.com/sindresorhus/electron-reloader) - Simple auto-reloading for Electron apps during development\n- [electron-debug](https://github.com/sindresorhus/electron-debug) - Adds useful debug features to your Electron app\n- [electron-context-menu](https://github.com/sindresorhus/electron-context-menu) - Context menu for your Electron app\n- [electron-dl](https://github.com/sindresorhus/electron-dl) - Simplified file downloads for your Electron app\n- [electron-unhandled](https://github.com/sindresorhus/electron-unhandled) - Catch unhandled errors and promise rejections in your Electron app\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Felectron-serve","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Felectron-serve","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Felectron-serve/lists"}