Redirect requests of current origin to another domain with Service Worker.

Overview

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

- name: Inject Service Worker
  uses: Menci/service-worker-redirect-origin@beta-v1
  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/<requested url> 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

$ yarn inject <wwwRoot> <targetBaseUrl> [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).

You might also like...

Easily redirect one entire domain to another with a serverless Cloudflare Worker.

Easily redirect one entire domain to another with a serverless Cloudflare Worker.

Domain Redirecting with Cloudflare Workers Easily redirect one entire domain to another with a serverless Cloudflare Worker. All paths and other data

Dec 11, 2022

Marketing-redirect - Redirect your customers from your marketing page to the application they're paying for

Marketing Redirect Do you have a marketing page and an app with two separate, bu

Feb 11, 2022

This is another Express + TypeScript + DDD (Domain Driven Design patterns) + IoC/DI (Inversion of control and Dependency injection) + Primsa ORM + API REST boilerplate.

Express-TS-DDD REST API This is another Express + TypeScript + DDD (Domain Driven Design patterns) + IoC/DI (Inversion of control and Dependency injec

Nov 3, 2022

Yet-Another-Relog-Mod - Just another relog mod. Call it YARM!

Yet-Another-Relog-Mod - Just another relog mod. Call it YARM!

Yet Another Relog Mod A relog mod with a name so long, you can just call it YARM for short. Features An aesthetic relog list design that follows my "p

Oct 19, 2022

may-be.gay is a service in which you can register your own sub-domain for your personal website

may-be.gay is a service in which you can register your own sub-domain for your personal website

may-be.gay is a service in which you can register your own sub-domain for your personal website. How to register New method (Recommended) Create a new

Dec 27, 2022

If you are a Slack browser user, this userscript will allow you to auto-redirect without Slack asking if you want to open on the desktop app.

If you are a Slack browser user, this userscript will allow you to auto-redirect without Slack asking if you want to open on the desktop app.

Auto-redirect for browser Slack users If you are a Slack browser user, this userscript will allow you to auto-redirect without Slack asking if you wan

Aug 23, 2022

Detect F12 open console, protect web static resources, support redirect, rewrite, callback strategies.

console-ban Detect F12 open browser console. protect web site static resources, support redirect, rewrite, custom callback strategies. Language: Engli

Dec 26, 2022

A simple JS example for NextAuth Google login with a popup window instead of redirect.

A simple JS example for NextAuth Google login with a popup window instead of redirect.

Dec 7, 2022

A service worker that buffers a full video, so when the video tag ask for ranges, these can be satisfied. Play + pause = buffer the whole video.

Full Video Buffer with Service Workers The specification of the preload attribute on a Video element won't allow you to fully buffer a video. This rep

Nov 2, 2022

โš™๏ธ Offline-capable Astro apps via SWSR (Service Worker Side Rendering)

Astro-service-worker โš™๏ธ Offline-capable Astro apps via SWSR (Service Worker Side Rendering) astro-service-worker will take your Astro SSR project, and

Dec 4, 2022

A common front-end/Service Worker-based Key/Value database based on CacheStorage

Cache-DB A common front-end/Service Worker-based Key/Value database based on CacheStorage const db = new CacheDB('ChenYFanDB') undefined await d

Sep 30, 2022

Persistent key/value data storage for your Browser and/or PWA, promisified, including file support and service worker support, all with IndexedDB. Perfectly suitable for your next (PWA) app.

Persistent key/value data storage for your Browser and/or PWA, promisified, including file support and service worker support, all with IndexedDB. Perfectly suitable for your next (PWA) app.

BrowstorJS ๐Ÿš€ ๐Ÿ’พ ๐Ÿ”’ Persistent key/value data storage for your Browser and/or PWA, promisified, including file support and service worker support, all

Aug 5, 2022

This is a demo for Remix SPA's via Service Worker. (doesn't currently work in Safari)

Welcome to Remix! Remix Docs Development From your terminal: npm run dev This starts your app in development mode, rebuilding assets on file changes.

Oct 2, 2022

PrivacyBot - A simple automated service to initiate CCPA deletion requests with databrokers

PROJECT NO LONGER SUPPORTED As of 9.28.21 this project has been depreciated and Google Oauth verification is not supported. You can still run the tool

Jan 3, 2023

EA Origin platform username checker

Origin EA Origin platform username checker. Instructions [?] Installation "npm i" [?] Fill in your Discord webhook details. "var webhookId = ``;" "va

Sep 29, 2022

Demo showcasing information leaks resulting from an IndexedDB same-origin policy violation in WebKit.

Safari 15 IndexedDB Leaks Description This demo showcases information leaks resulting from an IndexedDB same-origin policy violation in WebKit (a brow

Nov 5, 2022

A trivia website game based on origin of objects and concepts from around the world

Origin guesser is a quiz/trivia game in which the user is presented a word, object, or flag and offered a series of multiple choice answers to choose from as to the origin of that concept. Unlike other trivia games, this is concentrated only on origin of objects and concepts questions.

Feb 12, 2022

A discord bot that generates Discord Nitro, Hulu accounts, Origin, spotify and VPNs!

A discord bot that generates Discord Nitro, Hulu accounts, Origin, spotify and VPNs!

Discord-Account-Generator-Bot A discord bot that generates Discord Nitro, Hulu accounts, Origin, spotify and VPNs! Tutorial Basically download the fil

Oct 4, 2022
Comments
  • Perf: Proimse.any + AbortController

    Perf: Proimse.any + AbortController

    • Prefer Promise.any instead of home-baked promise race implementation.
      • Provide a light-weight Promise.any polyfill with ES2019 support
    • Use AbortController to abort a fired request, to potentially save bandwidth of the server
    opened by SukkaW 11
  • custom header options needed

    custom header options needed

    Using npm(even cdnjs!) as a cdn for your static web pages is a good option.My blog mentions this and uses this work too:

    https://blog.cyfan.top/p/d3c51290.html#%E5%85%A8%E7%AB%99NPM%E9%9D%99%E6%80%81%E5%8C%96

    But in most of the headers returned by cdn, the html file's content-type is text/plain(like jsDelivr,if you don't change it to text/html,you will recieve a plain text webpage),because they don't want you to distribute it as a web page.But ServiceWorker can solve it.

    You can open my blog in mainland China, my blog uses the sw written by myself to realize the distribution of the whole site to the npm mirror(most hit at eleme)

    opened by ChenYFan 32
Releases(beta-v3)
Owner
Menci
Where there is a SHELL, there is a WAY.
Menci
โš™๏ธ Offline-capable Astro apps via SWSR (Service Worker Side Rendering)

Astro-service-worker โš™๏ธ Offline-capable Astro apps via SWSR (Service Worker Side Rendering) astro-service-worker will take your Astro SSR project, and

Pascal Schilp 41 Dec 4, 2022
A tiny utility to asynchronously drive a namespace exposed through a Worker.

proxied-worker Social Media Photo by Ricardo Gomez Angel on Unsplash A tiny utility to asynchronously drive a namespace exposed through a Shared/Servi

Andrea Giammarchi 43 Dec 8, 2022
A tool library for handling window && iframe && worker communication based on the JSON RPC specification

rpc-shooter A tool library for handling window && iframe && worker communication based on the JSON RPC specification ไธ€ไธชๅŸบไบŽ JSON-RPC ่ง„่Œƒ็”จไบŽๅค„็† window && if

่‡ผ็Š€ 89 Dec 20, 2022
Cloudflare Worker that will allow you to progressively migrate files from an S3-compatible object store to Cloudflare R2.

A Cloudflare Worker for Progressive S3 to R2 Blog Post: https://kian.org.uk/progressive-s3-to-cloudflare-r2-migration-using-workers/ This is a Cloudfl

Kian 29 Dec 30, 2022
Send emails using Cloudflare Worker, for free.

Email API for Proselog. Not intended for use outside of Proselog, but it should work with any worker, without any configuration. import { sendEmail }

Proselog 65 Nov 7, 2022
Cloudflare Worker to make a R2 Bucket public!

r2-public-worker A Cloudflare Worker to make your R2 bucket public! Minimum Requirements Cloudflare Account wrangler >= 2.0.2 Note: Ensure you are usi

Cole Mackenzie 20 Sep 19, 2022
Type-safe and Promisified API for Web Worker and Iframe

?? You can help the author become a full-time open-source maintainer by sponsoring him on GitHub. typed-worker Install npm i typed-worker Usage Create

EGOIST 189 Dec 31, 2022
Using Cloudflare worker to generate host list from firebog to keep updated.

AdGuardCloudflareHostGenerator Use a cloudflare worker to generate a up to date list from FireBog's ticked list found at https://v.firebog.net/hosts/l

Jake Steele 14 Nov 30, 2022
Yet another concurrent priority task queue, yay!

YQueue Yet another concurrent priority task queue, yay! Install npm install yqueue Features Concurrency control Prioritized tasks Error handling for b

null 6 Apr 4, 2022
Making service workers easy so that your app is fast and reliable, even offline.

tulo.js Making service workers easy to use so that your app can be fast and reliable, even offline. Welcome to tulo.js, a service worker library that

OSLabs Beta 37 Nov 16, 2022