-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b644fd
commit 5699171
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package packages | ||
|
||
import ( | ||
"fmt" | ||
"github.com/gofiber/fiber/v2" | ||
"proxy/utils" | ||
"strings" | ||
) | ||
|
||
var CustomReplacer = map[string]string{ | ||
"chatnio": "https://chatnio.net", | ||
} | ||
|
||
func RegisterCustom(app *fiber.App) { | ||
for _, v := range CustomReplacer { | ||
app.All(fmt.Sprintf("/%s/*", v), func(c *fiber.Ctx) error { | ||
source := strings.TrimPrefix(c.Path(), fmt.Sprintf("/%s", v)) | ||
uri := fmt.Sprintf("%s%s", v, source) | ||
data, err := utils.Get(uri, nil) | ||
if err != nil { | ||
return c.SendString(fmt.Sprintf("error during get data: %s", err.Error())) | ||
} | ||
|
||
return c.SendString(data) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 RegisterEsm(app *fiber.App) { | ||
app.All("/esm/*", func(c *fiber.Ctx) error { | ||
source := strings.TrimPrefix(c.Path(), "/esm") | ||
uri := fmt.Sprintf("https://cdn.jsdelivr.net/npm%s", source) | ||
data, err := utils.Get(uri, nil) | ||
if err != nil { | ||
return c.SendString(fmt.Sprintf("error during get data: %s", err.Error())) | ||
} | ||
|
||
data = strings.Replace(data, "https://esm.sh", "/esm", -1) | ||
|
||
return c.SendString(data) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 RegisterUnpkg(app *fiber.App) { | ||
app.All("/unpkg/*", func(c *fiber.Ctx) error { | ||
source := strings.TrimPrefix(c.Path(), "/unpkg") | ||
uri := fmt.Sprintf("https://unpkg.com%s", source) | ||
data, err := utils.Get(uri, nil) | ||
if err != nil { | ||
return c.SendString(fmt.Sprintf("error during get data: %s", err.Error())) | ||
} | ||
|
||
data = strings.Replace(data, "https://unpkg.com", "/unpkg", -1) | ||
|
||
return c.SendString(data) | ||
}) | ||
} |