typedserver/ts/servertools/classes.feed.ts
2023-03-30 15:15:48 +02:00

36 lines
1.1 KiB
TypeScript

import { Handler } from './classes.handler.js';
import { Server } from './classes.server.js';
import * as plugins from '../typedserver.plugins.js';
export class Feed {
public smartexpressRef: Server;
public smartfeedInstance = new plugins.smartfeed.Smartfeed();
public feedHandler = new Handler('GET', async (req, res) => {
if (!this.smartexpressRef.options.feedMetadata) {
res.status(500);
res.write('feed metadata is missing');
res.end();
return;
}
if (!this.smartexpressRef.options.articleGetterFunction) {
res.status(500);
res.write('no article getter function defined.');
res.end();
return;
}
const xmlString = await this.smartfeedInstance.createFeedFromArticleArray(
this.smartexpressRef.options.feedMetadata,
await this.smartexpressRef.options.articleGetterFunction()
);
res.type('.xml');
res.write(xmlString);
res.end();
});
constructor(smartexpressRefArg: Server) {
this.smartexpressRef = smartexpressRefArg;
this.smartexpressRef.addRouteBefore('/feed', this.feedHandler);
}
}