diff --git a/src/app.ts b/src/app.ts index 38226d2..a2675ee 100644 --- a/src/app.ts +++ b/src/app.ts @@ -5,9 +5,9 @@ import Fastify from "fastify"; import fastifyView from "@fastify/view"; import ejs from "ejs"; -import mainRoute from "./routes/main"; +import getRoute from "./routes/get"; import parseRoute from "./routes/parse"; -import startRoute from "./routes/start"; +import indexRoute from "./routes/index"; class App { config: IConfigService; @@ -27,9 +27,9 @@ class App { }, }); - fastify.register(mainRoute); + fastify.register(indexRoute); + fastify.register(getRoute); fastify.register(parseRoute); - fastify.register(startRoute); fastify.listen({ port: Number(this.config.get("PORT")) }, (err) => { err && console.log(err); diff --git a/src/handlers/main.ts b/src/handlers/main.ts index d559c61..7351a6c 100644 --- a/src/handlers/main.ts +++ b/src/handlers/main.ts @@ -1,16 +1,18 @@ import { IHandlerOutput } from "./handler.interface"; - import axios from "../types/axios"; + import { JSDOM } from "jsdom"; +import { DOMWindow } from "jsdom"; import readability from "./readability"; import google from "./google"; -import { DOMWindow } from "jsdom"; + export default async function handlePage( url: string, originalUrl: string, engine?: string ): Promise { + if (engine && engineList.indexOf(engine) === -1) { throw new Error("Invalid engine"); } @@ -21,7 +23,7 @@ export default async function handlePage( const UrlParsed = new URL(originalUrl); [...window.document.getElementsByTagName("a")].forEach((link) => { - link.href = `${UrlParsed.origin}/?url=${link.href}${ + link.href = `${UrlParsed.origin}/get?url=${link.href}${ engine ? `&engine=${engine}` : "" }`; }); diff --git a/src/routes/main.ts b/src/routes/get.ts similarity index 86% rename from src/routes/main.ts rename to src/routes/get.ts index 0c7f388..99e6a08 100644 --- a/src/routes/main.ts +++ b/src/routes/get.ts @@ -4,8 +4,8 @@ import { GetRequest } from "../types/requests"; import handlePage from "../handlers/main"; import { generateOriginUrl } from "../utils"; -export default async function mainRoute(fastify: FastifyInstance) { - fastify.get("/", async (request: GetRequest, reply) => { +export default async function getRoute(fastify: FastifyInstance) { + fastify.get("/get", async (request: GetRequest, reply) => { const remoteUrl = request.query.url; const engine = request.query.engine; diff --git a/src/routes/start.ts b/src/routes/index.ts similarity index 60% rename from src/routes/start.ts rename to src/routes/index.ts index 1bf780b..7d03dc1 100644 --- a/src/routes/start.ts +++ b/src/routes/index.ts @@ -1,8 +1,8 @@ import { FastifyInstance } from "fastify"; import { engineList } from "../handlers/main"; -export default async function parseRoute(fastify: FastifyInstance) { - fastify.get("/start", async (_, reply) => { +export default async function indexRoute(fastify: FastifyInstance) { + fastify.get("/", async (_, reply) => { return reply.view("/templates/start.ejs", { engineList }); }); } diff --git a/templates/get.ejs b/templates/get.ejs new file mode 100644 index 0000000..c2a64c9 --- /dev/null +++ b/templates/get.ejs @@ -0,0 +1,14 @@ + + + + + + + + <%= parsed.title %> + + +

<%= parsed.title %>

+
<%- parsed.content %>
+ + diff --git a/templates/index.ejs b/templates/index.ejs index c2a64c9..bd22cd1 100644 --- a/templates/index.ejs +++ b/templates/index.ejs @@ -1,14 +1,80 @@ +<% const desc = "txtdot is a HTTP proxy that parses text, links and pictures from pages reducing internet traffic, removing ads and heavy scripts" %> - + - - <%= parsed.title %> + + txt. main page + + -

<%= parsed.title %>

-
<%- parsed.content %>
+
+
+

txt.

+

<%= desc %>

+
+
+
+ +
+
+ +
+
+
+ + +
+
+ + +
+
+
+
diff --git a/templates/start.ejs b/templates/start.ejs deleted file mode 100644 index 64c04ca..0000000 --- a/templates/start.ejs +++ /dev/null @@ -1,80 +0,0 @@ -<% const desc = "txtdot is a HTTP proxy that parses text, links and pictures from pages reducing internet traffic, removing ads and heavy scripts" %> - - - - - - - - txt. main page - - - - -
-
-

txt.

-

<%= desc %>

-
-
-
- -
-
- -
-
-
- - -
-
- - -
-
-
-
- -