txtdot/src/routes/api/parse.ts
Artemy Egorov 8f707c800e
Timeout (#70)
* fix: long response time due to many <a>...

... without hrefs. It's a temporary measure until it's clear how to deal with such performance issues.

* perf: remove jsdom install linkedom

* feat: timeout

But still this timeout works only for the time of transfer of the page itself, not its processing by the server

* fix: links

* format
2023-12-13 21:08:24 +04:00

32 lines
724 B
TypeScript

import { FastifyInstance } from 'fastify';
import {
EngineRequest,
IParseSchema,
parseSchema,
} from '../../types/requests/api';
import handlePage from '../../handlers/main';
import { generateRequestUrl } from '../../utils/generate';
export default async function parseRoute(fastify: FastifyInstance) {
fastify.get<IParseSchema>(
'/api/parse',
{ schema: parseSchema },
async (request: EngineRequest) => {
return {
data: await handlePage(
request.query.url,
generateRequestUrl(
request.protocol,
request.hostname,
request.originalUrl
),
request.query.engine
),
error: null,
};
}
);
}