https://github.com/menci/service-worker-redirect-origin
Redirect requests of current origin to another domain with Service Worker.
https://github.com/menci/service-worker-redirect-origin
Last synced: about 1 year ago
JSON representation
Redirect requests of current origin to another domain with Service Worker.
- Host: GitHub
- URL: https://github.com/menci/service-worker-redirect-origin
- Owner: Menci
- License: mit
- Created: 2022-01-05T13:22:58.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-12-13T15:19:09.000Z (over 3 years ago)
- Last Synced: 2025-04-18T15:17:32.486Z (over 1 year ago)
- Language: TypeScript
- Size: 30.3 KB
- Stars: 12
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Service Worker to Redirect Origin
This is a tool for your static website which could intercept all `GET` requests of the origin domain and redirect them to a given base-URL. Such as `/index.html` to `https://cdn.example.com/index.html`.
It's useful when your origin domain have no ICP license but you want to optimize mainland China routing.
# Usage
## GitHub Action
```yaml
- name: Inject Service Worker
uses: Menci/service-worker-redirect-origin@beta-v2
with:
# The directory containing your built static website files.
www-root: public
# The target base-URL to redirect to.
target-base-url: https://cdn.example.com/ # Remember to end with a "/"
# If https://cdn.example.com/ responds with 404, it's will be fetched.
# Omit to fallback to origin.
http-404-page: 404.html
# The script filename of service worker. Will be written to the `www-root` directory.
# By default `sw.js`.
service-worker-filename: sw.js
```
## Node.js
```bash
$ yarn inject [404Page] [serviceWorkerFilename]
```
See the explanation for each arguments above in GitHub Action usage.
# Limitations
It will replace your existing Service Worker in your site (if any).