Skip to content

Commit 6bcf88c

Browse files
committed
feat: protect endpoint
Signed-off-by: Gašper Grom <[email protected]>
1 parent a9ddfff commit 6bcf88c

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

frontend/app/components/modules/project/services/community.api.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class ProjectCommunityApiService {
9494
query: () => Record<string, string | number | string[] | undefined | null>,
9595
): QueryFunction<Pagination<CommunityMentions>, readonly unknown[], number> {
9696
return async ({ pageParam = 0 }) =>
97-
await $fetch(`/api/project/${query().projectSlug}/community`, {
97+
await $fetch(`/api/community/list`, {
9898
params: {
9999
page: pageParam,
100100
...query(),

frontend/server/api/project/[slug]/community.ts renamed to frontend/server/api/community/list.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ import { Pagination } from '~~/types/shared/pagination';
55
import { CommunityMentions } from '~~/types/community/community';
66

77
export default defineEventHandler(async (event): Promise<Pagination<CommunityMentions>> => {
8-
const { slug } = event.context.params as Record<string, string>;
8+
const query = getQuery(event);
9+
const projectSlug = query.projectSlug as string;
910

10-
if (!slug) {
11+
if (!projectSlug) {
1112
throw createError({
1213
statusCode: 400,
1314
statusMessage: 'Project slug is required',
1415
});
1516
}
1617

17-
const query = getQuery(event);
18-
1918
const page: number = (query.page as number) || 0;
2019
const pageSize: number = (query.pageSize as number) || 20;
2120
const platforms = Array.isArray(query.platforms)
@@ -47,7 +46,7 @@ export default defineEventHandler(async (event): Promise<Pagination<CommunityMen
4746
keywords,
4847
sentiments,
4948
languages,
50-
projectSlug: slug,
49+
projectSlug,
5150
});
5251

5352
return {

frontend/server/middleware/jwt-auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const isJWT = (token: string) => {
1313
export default defineEventHandler(async (event) => {
1414
const url = getRouterParam(event, '_') || event.node.req.url || '';
1515

16-
const protectedRoutes = ['/api/report'];
16+
const protectedRoutes = ['/api/report', '/api/community/list'];
1717
const protectedAndPermissionRoutes = ['/api/chat'];
1818

1919
const isProtectedRoute = [...protectedRoutes, ...protectedAndPermissionRoutes].some((route) =>

frontend/setup/caching.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default {
1515
'/api/health/live': { cache: false },
1616
'/api/seo/og-image': { cache: false },
1717
'/api/report': { cache: false },
18+
'/api/community/list': { cache: { maxAge: longCache, base: 'redis' } },
1819
'/api/community/**': { cache: false },
1920
'/api/search': { cache: { maxAge: longCache, base: 'redis' } },
2021
'/api/category': { cache: { maxAge: longCache, base: 'redis' } },

0 commit comments

Comments
 (0)