Skip to content

Commit

Permalink
Add: Host Redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
AmosHuKe committed May 24, 2024
1 parent dd55090 commit 7e03237
Show file tree
Hide file tree
Showing 13 changed files with 4,018 additions and 3 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/compile_host_redirect_js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Compile host-redirect.min.js

on:
workflow_dispatch:
push:
branches:
- main
paths:
- "firebase.json"
- "tool/host-redirect/**"

permissions:
contents: write

env:
NODE_VERSION: 20

jobs:
compile_host_redirect_js:
if: ${{ github.actor.login != 'cfug-dev' &&
github.repository == 'cfug/flutter.cn' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Build JS
run: bash ./tool/host-redirect/build.sh
shell: bash
632 changes: 629 additions & 3 deletions firebase.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/content/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
body_class: landing-page not-found
permalink: /404.html
sitemap: false
js:
- url: /assets/js/host-redirect.min.js
---

<div class="not-found__wrapper">
Expand Down
2 changes: 2 additions & 0 deletions src/content/assets/js/host-redirect.min.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions tool/host-redirect/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules/
build/
report/
coverage/
.AppleDouble
.vscode/
/.development
/.developmentx
/.xdevelopment
21 changes: 21 additions & 0 deletions tool/host-redirect/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Amos<[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
24 changes: 24 additions & 0 deletions tool/host-redirect/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## 临时的重定向方案

由于 OSS 部分限制的问题,
无法将大量重定向逻辑在服务端直接使用(类似 Nginx、Apache 等),

所有无法访问的链接会被重定向至 404 页,
该方案利用 404 页,
将 firebase.json 内的重定向逻辑运行在 404 页面。

关于 firebase.json 内重定向的相关资料:
> https://firebase.google.cn/docs/hosting/full-config?hl=zh-cn#redirects
### 环境

- node v20.11.0
- npm v10.2.4

### 使用

```sh
npm install

npm run build # ./build/host-redirect.min.js
```
16 changes: 16 additions & 0 deletions tool/host-redirect/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/bash

cd tool/host-redirect
npm install
npm run build

cd -
cp ./tool/host-redirect/build/host-redirect.min.js ./src/content/assets/js/host-redirect.min.js

git init
git config --global user.name "cfug-dev"
git config --global user.email "[email protected]"

git add ./src/content/assets/js/host-redirect.min.js
git commit -m "[sync] Update: host-redirect.min.js"
git push -u -f
21 changes: 21 additions & 0 deletions tool/host-redirect/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "host_redirect",
"version": "1.0.0",
"description": "",
"main": "./src/index.js",
"scripts": {
"build": "node ./src/generate_firebase_data.js && webpack"
},
"author": "AmosHuKe",
"homepage": "https://github.com/cfug/flutter.cn/tree/main/tool/host-redirect",
"license": "MIT",
"devDependencies": {
"webpack": "^5.91.0",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"minimatch": "^9.0.4",
"path-to-regexp": "^6.2.2",
"re2js": "^0.4.1"
}
}
Loading

0 comments on commit 7e03237

Please sign in to comment.