Files
bewcloud/routes/news.tsx
Bruno Bernardino e337859a22 Implement a more robust Config (#60)
* Implement a more robust Config

This moves the configuration variables from the `.env` file to a new `bewcloud.config.ts` file. Note that DB connection and secrets are still in the `.env` file.

This will allow for more reliable and easier personalized configurations, and was a requirement to start working on adding SSO (#13).

For now, `.env`-based config will still be allowed and respected (overriden by `bewcloud.config.ts`), but in the future I'll probably remove it (some major upgrade).

* Update deploy script to also copy the new config file
2025-05-25 15:48:53 +01:00

35 lines
1015 B
TypeScript

import { Handlers, PageProps } from 'fresh/server.ts';
import { FreshContextState, NewsFeedArticle } from '/lib/types.ts';
import { AppConfig } from '/lib/config.ts';
import { ArticleModel } from '/lib/models/news.ts';
import Articles from '/islands/news/Articles.tsx';
interface Data {
userArticles: NewsFeedArticle[];
}
export const handler: Handlers<Data, FreshContextState> = {
async GET(request, context) {
if (!context.state.user) {
return new Response('Redirect', { status: 303, headers: { 'Location': `/login` } });
}
if (!(await AppConfig.isAppEnabled('news'))) {
return new Response('Redirect', { status: 303, headers: { 'Location': `/dashboard` } });
}
const userArticles = await ArticleModel.list(context.state.user.id);
return await context.render({ userArticles });
},
};
export default function News({ data }: PageProps<Data, FreshContextState>) {
return (
<main>
<Articles initialArticles={data?.userArticles || []} />
</main>
);
}