Files
oneuptime/App/FeatureSet/Home/API/BlogAPI.ts

77 lines
2.3 KiB
TypeScript

import Express, { ExpressApplication, ExpressRequest, ExpressResponse } from "CommonServer/Utils/Express";
import BlogPost from "../Utils/BlogPost";
import BlogPostUtil from "../Utils/BlogPost";
import { ViewsPath } from "../Utils/Config";
import logger from 'CommonServer/Utils/Logger';
import ServerErrorUtil from "../Utils/ServerError";
import NotFoundUtil from "../Utils/NotFound";
const app: ExpressApplication = Express.getExpressApp();
app.get('/blog/post/:file', async (req: ExpressRequest, res: ExpressResponse) => {
try {
const fileName: string = req.params['file'] as string;
const blogPost: BlogPost | null = await BlogPostUtil.getBlogPost(fileName);
if(!blogPost) {
return NotFoundUtil.renderNotFound(res);
}
res.render(`${ViewsPath}/Blog/Post`, {
support: false,
footerCards: true,
cta: true,
blackLogo: false,
requestDemoCta: false,
blogPost: blogPost,
});
} catch (e) {
logger.error(e);
return ServerErrorUtil.rednerServerError(res);
}
});
// List all blog posts with tag
app.get('/blog/tag/:tagName', async (req: ExpressRequest, res: ExpressResponse) => {
try {
const fileName: string = req.params['file'] as string;
const blogPost: BlogPost = await BlogPostUtil.getBlogPost(fileName);
res.render(`${ViewsPath}/Blog/ListByTag`, {
support: false,
footerCards: true,
cta: true,
blackLogo: false,
requestDemoCta: false,
blogPost: blogPost,
});
} catch (e) {
logger.error(e);
return res.redirect('/server-error');
}
});
// main blog page
app.get('/blog', async (req: ExpressRequest, res: ExpressResponse) => {
try {
const fileName: string = req.params['file'] as string;
const blogPost: BlogPost = await BlogPostUtil.getBlogPost(fileName);
res.render(`${ViewsPath}/Blog/List`, {
support: false,
footerCards: true,
cta: true,
blackLogo: false,
requestDemoCta: false,
blogPost: blogPost,
});
} catch (e) {
logger.error(e);
return res.redirect('/server-error');
}
});