From eafdcf62409c8a69d4f6f61f5f845beaaba53702 Mon Sep 17 00:00:00 2001 From: Artemy Date: Wed, 16 Aug 2023 09:43:43 +0300 Subject: [PATCH] feat: raw html page For custom user clients --- src/app.ts | 2 ++ src/routes/raw-html.ts | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/routes/raw-html.ts diff --git a/src/app.ts b/src/app.ts index 437c11d..7fad46b 100644 --- a/src/app.ts +++ b/src/app.ts @@ -11,6 +11,7 @@ import ejs from "ejs"; import getRoute from "./routes/get"; import parseRoute from "./routes/parse"; import indexRoute from "./routes/index"; +import rawHtml from "./routes/raw-html"; class App { config: IConfigService; @@ -38,6 +39,7 @@ class App { fastify.register(indexRoute); fastify.register(getRoute); fastify.register(parseRoute); + fastify.register(rawHtml); fastify.listen({ port: Number(this.config.get("PORT")) }, (err) => { err && console.log(err); diff --git a/src/routes/raw-html.ts b/src/routes/raw-html.ts new file mode 100644 index 0000000..4ac60d8 --- /dev/null +++ b/src/routes/raw-html.ts @@ -0,0 +1,20 @@ +import { FastifyInstance } from "fastify"; + +import { GetRequest } from "../types/requests"; +import handlePage from "../handlers/main"; +import { generateRequestUrl } from "../utils"; + +export default async function rawHtml(fastify: FastifyInstance) { + fastify.get("/raw-html", async (request: GetRequest) => { + return ( + await handlePage( + request.query.url, + generateRequestUrl( + request.protocol, + request.hostname, + request.originalUrl + ) + ) + ).content; + }); +}