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; + }); +}