mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-05 05:18:12 +03:00
add cdn redirects
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import t from "tap";
|
||||
import { CDNStoreOrOverwrite } from "../../../lib/cdn/cdn";
|
||||
import { CloseAllConnections } from "../../../test-utils/close-connections";
|
||||
import mockApi from "../../../test-utils/mock-api";
|
||||
|
||||
t.test("GET /cdn", (t) => {
|
||||
t.test("Should return this content at the CDN.", async (t) => {
|
||||
await CDNStoreOrOverwrite("/foo", "hello world");
|
||||
|
||||
const res = await mockApi.get("/cdn/foo");
|
||||
|
||||
t.equal(res.body.toString(), "hello world");
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Router } from "express";
|
||||
import { CDNRedirect } from "../../../lib/cdn/cdn";
|
||||
|
||||
const router: Router = Router({ mergeParams: true });
|
||||
|
||||
/**
|
||||
* Redirect all /cdn/ requests to this servers' CDN. This is so the client can refer to
|
||||
* (url)/cdn, and still have it resolve to our CDN internally.
|
||||
*
|
||||
* @example <script src="/cdn/foo"></script> instead of <script src= "{{CDN_URL}}/foo"></script>
|
||||
*
|
||||
* @name GET /cdn/*
|
||||
*/
|
||||
router.get("*", (req, res) => {
|
||||
console.log(req.originalUrl);
|
||||
const url = req.originalUrl.replace(/^\/cdn/u, "");
|
||||
console.log(url);
|
||||
return CDNRedirect(res, url);
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -3,6 +3,7 @@ import { SetRequestPermissions } from "../middleware/auth";
|
||||
import { RateLimitMiddleware } from "../middleware/rate-limiter";
|
||||
import apiRouterV1 from "./api/v1/router";
|
||||
import irRouter from "./ir/router";
|
||||
import cdnReRouter from "./cdn/router";
|
||||
|
||||
const router: Router = Router({ mergeParams: true });
|
||||
|
||||
@@ -15,5 +16,6 @@ router.use("/ir", irRouter);
|
||||
// but also may require custom authentication.
|
||||
router.use(SetRequestPermissions);
|
||||
router.use("/api/v1", apiRouterV1);
|
||||
router.use("/cdn", cdnReRouter);
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user