https://github.com/anonrig/electron-server
Use Fastify inside an Electron app without consuming a port
https://github.com/anonrig/electron-server
Last synced: about 1 year ago
JSON representation
Use Fastify inside an Electron app without consuming a port
- Host: GitHub
- URL: https://github.com/anonrig/electron-server
- Owner: anonrig
- Created: 2022-07-12T15:58:17.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-07-13T21:43:37.000Z (almost 4 years ago)
- Last Synced: 2025-04-15T12:52:50.852Z (about 1 year ago)
- Language: TypeScript
- Homepage: https://npmjs.com/package/electron-server
- Size: 29.3 KB
- Stars: 27
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
## Electron Server
A super-fast and easy-to-use library to use Fastify, and it's ecosystem inside an Electron application without the need of exposing (and consuming) a port.
### Use-cases
- Running GraphQL in your Electron application.
- Running Next.js using `fastify-nextjs` to create `chrome://extensions` like pages for your Electron app
- Communication between main and renderer process using HTTP methods
- Static file (assets) sharing between renderer process and the main process
### Install
To install `electron-server` in an existing project as a dependency:
Install with npm:
```sh
npm i electron-server
```
Install with pnpm:
```sh
pnpm add electron-server
```
### Example
```js
// Require fastify and instantiate it.
const Fastify = require('fastify')
const server = Fastify({ ignoreTrailingSlash: true })
server.get('/hello-world', () => ({ hello: 'world' }))
// Require registerProtocol and call it on your root file.
const { registerProtocol } = require('electron-server')
// Register custom scheme to Electron
registerProtocol({
scheme: 'my-scheme',
server,
})
app.whenReady().then(() => {
const win = new BrowserWindow({
width: 800,
height: 600,
});
// Visit the custom scheme
win.loadURL("my-protocol://hello-world");
});
```
Do you want to run the example? Head to the Playground.