Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfixes - December 2024 #60

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ NEXT_PUBLIC_DOWNLOADS_URL=http://localhost:10000
LOCAL_DOWNLOADS_URL=http://localhost:10000

NEXT_REVALIDATE_TIME=600
NEXT_INTERNAL_AUTH_SECRET=SOMETHING_HERE

STRAPI_API_TOKEN=YOUR_TOKEN_HERE
NEXT_PUBLIC_STRAPI_URL=http://localhost:1337
Expand Down
12 changes: 12 additions & 0 deletions src/app/api/cache/revalidate/cms/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { NextResponse } from 'next/server';
import { revalidateTag } from 'next/cache';
import { NEXT_CACHE_TAG_STRAPI } from '@lib/constants/app';

export const POST = () => {
revalidateTag(NEXT_CACHE_TAG_STRAPI);

return NextResponse.json({
revalidated: true,
date: new Date().toISOString()
}, { status: 200 });
};
1 change: 1 addition & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ declare global {
LOCAL_DOWNLOADS_URL?: string

NEXT_REVALIDATE_TIME?: string
NEXT_INTERNAL_AUTH_SECRET?: string

STRAPI_API_TOKEN?: string
NEXT_PUBLIC_STRAPI_URL?: string
Expand Down
1 change: 1 addition & 0 deletions src/lib/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const NEXT_PUBLIC_DOWNLOADS_URL = process.env.NEXT_PUBLIC_DOWNLOADS_URL!;
export const LOCAL_DOWNLOADS_URL = process.env.LOCAL_DOWNLOADS_URL!;

export const NEXT_REVALIDATE_TIME = process.env.NEXT_REVALIDATE_TIME ? parseInt(process.env.NEXT_REVALIDATE_TIME, 10) : 3600;
export const NEXT_INTERNAL_AUTH_SECRET = process.env.NEXT_INTERNAL_AUTH_SECRET!;

export const STRAPI_API_TOKEN = process.env.STRAPI_API_TOKEN!;
export const NEXT_PUBLIC_STRAPI_URL = process.env.NEXT_PUBLIC_STRAPI_URL!;
2 changes: 2 additions & 0 deletions src/lib/constants/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ export const PEPTIDE_ATTRIBUTE_MAX_DECIMALS = 4;
export const PEPTIDE_SCORE_DECIMALS = 2;

export const DEFAULT_AUTO_RELOAD_INTERVAL_SECONDS = 5;

export const NEXT_CACHE_TAG_STRAPI = 'strapi-cms';
7 changes: 7 additions & 0 deletions src/lib/next/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { NextRequest } from 'next/server';
import { NEXT_INTERNAL_AUTH_SECRET } from '@lib/config/app';

export const isInternalApiRequestAuthenticated = (req: NextRequest) => {
const token = req.headers.get('X-Auth-Secret');
return token === NEXT_INTERNAL_AUTH_SECRET;
};
4 changes: 2 additions & 2 deletions src/lib/services/bioApi/helpers/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export const SUPPORTED_ALGORITHMS = {
local: 'Local (Smith-Waterman)',
global: 'Global (Needleman-Wunsch)'
};
export const SUPPORTED_CRITERIA = ['avg', 'max', 'min'];
export const SUPPORTED_CRITERIA = ['max', 'min', 'avg'];

export const DEFAULT_MATRIX_NAME = 'BLOSUM62';
export const DEFAULT_ALGORITHM = 'local';
export const DEFAULT_CRITERION = 'avg';
export const DEFAULT_CRITERION = 'max';

export const DEFAULT_SINGLE_ALIGNMENT_OPTIONS: SingleQueryAlignmentOptions = {
matrix: DEFAULT_MATRIX_NAME,
Expand Down
5 changes: 3 additions & 2 deletions src/lib/services/strapi/graphql/client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'server-only';
import { ApolloClient, ApolloLink, HttpLink, InMemoryCache, NormalizedCacheObject, OperationVariables, QueryOptions } from '@apollo/client';
import { DeepPartial } from 'utility-types';
import { NEXT_REVALIDATE_TIME, NEXT_PUBLIC_STRAPI_URL, STRAPI_API_TOKEN } from '@lib/config/app';
import { NEXT_PUBLIC_STRAPI_URL, STRAPI_API_TOKEN } from '@lib/config/app';
import { NEXT_CACHE_TAG_STRAPI } from '@lib/constants/app';

const httpLink = new HttpLink({
uri: `${NEXT_PUBLIC_STRAPI_URL}/graphql`,
Expand All @@ -13,7 +14,7 @@ const httpLink = new HttpLink({
Authorization: `Bearer ${STRAPI_API_TOKEN}`
},
next: {
revalidate: NEXT_REVALIDATE_TIME
tags: [NEXT_CACHE_TAG_STRAPI]
}
});
}
Expand Down
22 changes: 22 additions & 0 deletions src/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { NextRequest, NextResponse } from 'next/server';
import { isInternalApiRequestAuthenticated } from '@lib/next/auth';

export const config = {
matcher: ['/api/:path*']
};

const middleware = (req: NextRequest) => {
if (!req.nextUrl.pathname.startsWith('/api')) {
return NextResponse.next();
}

if (!isInternalApiRequestAuthenticated(req)) {
return NextResponse.json({
message: 'You are not authenticated.'
}, { status: 401 });
}

return NextResponse.next();
};

export default middleware;
Loading