Format: line breaks
This commit is contained in:
parent
3a1fac2b65
commit
c17bbdbfda
11
src/app.ts
11
src/app.ts
@ -1,18 +1,25 @@
|
||||
import { IConfigService } from "./config/config.interface";
|
||||
import { ConfigService } from "./config/config.service";
|
||||
|
||||
import NodeCache from "node-cache";
|
||||
|
||||
import { readability } from "./handlers/readability";
|
||||
import getCorrespondingReaderView from "./handlers/main";
|
||||
|
||||
import Fastify from "fastify";
|
||||
import middie from "@fastify/middie";
|
||||
|
||||
import { Cached, EngineRequest, GetRequest } from "./schema/requests.types";
|
||||
|
||||
class App {
|
||||
config: IConfigService;
|
||||
cache: NodeCache;
|
||||
|
||||
constructor() {
|
||||
this.config = new ConfigService();
|
||||
this.cache = new NodeCache({ stdTTL: 100, checkperiod: 120 });
|
||||
}
|
||||
|
||||
async init() {
|
||||
const fastify = Fastify({
|
||||
logger: true,
|
||||
@ -22,9 +29,8 @@ class App {
|
||||
|
||||
fastify.use((req, res, next) => {
|
||||
const url = req.originalUrl || req.url || "/";
|
||||
const purge = req.query.purge ? true : false;
|
||||
|
||||
if (purge) {
|
||||
if (req.query.purge) {
|
||||
this.cache.del(url);
|
||||
next();
|
||||
}
|
||||
@ -66,6 +72,7 @@ class App {
|
||||
content: parsed,
|
||||
contentType: "text/json",
|
||||
});
|
||||
|
||||
return parsed;
|
||||
});
|
||||
|
||||
|
@ -3,8 +3,10 @@ import { IConfigService } from "./config.interface";
|
||||
|
||||
export class ConfigService implements IConfigService {
|
||||
private config: DotenvParseOutput;
|
||||
|
||||
constructor() {
|
||||
const { error, parsed } = config();
|
||||
|
||||
if (error) {
|
||||
throw new Error(".env file not found");
|
||||
}
|
||||
@ -18,6 +20,7 @@ export class ConfigService implements IConfigService {
|
||||
|
||||
get(key: string): string {
|
||||
const res = this.config[key];
|
||||
|
||||
if (!res) {
|
||||
throw new Error(`Key ${key} not found`);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import { IHandlerOutput } from "./handler.interface";
|
||||
export async function readability(url: string): Promise<IHandlerOutput> {
|
||||
const response = await axios.get(url);
|
||||
const dom = new JSDOM(response.data, { url: url });
|
||||
|
||||
const reader = new Readability(dom.window.document);
|
||||
const parsed = reader.parse();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user