Skip to content

Commit

Permalink
add cdnjs proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
zmh-program committed Oct 1, 2023
1 parent 1ab61ae commit 4788e1f
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,36 @@ GoogleFonts, JsDelivr, ESM, Unpkg等总局代理,加速网站国内访问

GoogleFonts, JsDelivr, ESM, Unpkg, etc. General Agency, accelerating the domestic access to the site

</div>
</div>

### 🚀 Usage | 用法

- Google Fonts
> Note: 请将风格符号`+`替换为`-`,例如`Roboto+Mono`替换为`Roboto-Mono`
```html
https://open.lightxi.com/fonts/<font-family>
```

- JsDelivr
```html
https://open.lightxi.com/jsdelivr/<path>
```

- ESM
```html
https://open.lightxi.com/esm/<path>
```

- Unpkg
```html
https://open.lightxi.com/unpkg/<path>
```

- CDNJS
```html
https://open.lightxi.com/cdnjs/<path>
```

### 📝 License | 许可证
CC-0-1.0 License
7 changes: 7 additions & 0 deletions app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ function App() {
https://open.lightxi.com/unpkg/<strong className={`point`}>[email protected]/umd/react.production.min.js</strong>
</div>
</div>

<div className={`app`}>
<a className={`title`} href={`https://cdnjs.com`} target={`_blank`}>Cdnjs</a>
<div className={`code`}>
https://open.lightxi.com/cdnjs/<strong className={`point`}>ajax/libs/vue/3.3.4/vue.cjs.js</strong>
</div>
</div>
</div>
<div className={`card-footer`}>
powered by
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func main() {
packages.RegisterFonts(app)
packages.RegisterEsm(app)
packages.RegisterUnpkg(app)
packages.RegisterCdnJs(app)
packages.RegisterCustom(app)
}

Expand Down
23 changes: 23 additions & 0 deletions packages/cdnjs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package packages

import (
"fmt"
"github.com/gofiber/fiber/v2"
"proxy/utils"
"strings"
)

func RegisterCdnJs(app *fiber.App) {
app.All("/cdnjs/*", func(c *fiber.Ctx) error {
source := strings.TrimPrefix(c.Path(), "/cdnjs")
uri := fmt.Sprintf("https://cdnjs.cloudflare.com%s", source)
data, err := utils.Get(uri, nil)
if err != nil {
return Catch(c, err)
}

return End(c, data, func(data string) string {
return strings.Replace(data, "/ajax/libs", "/cdnjs/ajax/libs", -1)
})
})
}

0 comments on commit 4788e1f

Please sign in to comment.