Skip to content

Commit

Permalink
feat: remove cognito from server runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
solufa committed Jul 5, 2024
1 parent 9c58bcb commit 5d481d9
Show file tree
Hide file tree
Showing 10 changed files with 708 additions and 598 deletions.
3 changes: 0 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ ENV NEXT_PUBLIC_API_BASE_PATH=$NEXT_PUBLIC_API_BASE_PATH
ENV SERVER_PORT=$SERVER_PORT

ARG NEXT_PUBLIC_COGNITO_POOL_ENDPOINT
ARG COGNITO_ACCESS_KEY
ARG COGNITO_SECRET_KEY
ARG COGNITO_REGION
ARG COGNITO_USER_POOL_ID
ARG COGNITO_USER_POOL_CLIENT_ID
ARG DATABASE_URL
Expand Down
3 changes: 0 additions & 3 deletions server/.env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
COGNITO_ACCESS_KEY=cognito-access-key
COGNITO_SECRET_KEY=cognito-secret-key
COGNITO_REGION=ap-northeast-1
S3_ENDPOINT=http://localhost:9000
S3_BUCKET=app
S3_ACCESS_KEY=minio
Expand Down
2 changes: 0 additions & 2 deletions server/api/health/controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { cognito } from 'service/cognito';
import { prismaClient } from 'service/prismaClient';
import { s3 } from 'service/s3Client';
import { defineController } from './$relay';
Expand All @@ -10,7 +9,6 @@ export default defineController(() => ({
server: 'ok',
db: await prismaClient.$queryRaw`SELECT CURRENT_TIMESTAMP;`.then(() => 'ok' as const),
storage: await s3.health().then(() => 'ok' as const),
cognito: await cognito.health().then(() => 'ok' as const),
},
}),
}));
2 changes: 1 addition & 1 deletion server/api/health/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import type { DefineMethods } from 'aspida';

export type Methods = DefineMethods<{
get: {
resBody: Record<'server' | 'db' | 'storage' | 'cognito', 'ok'>;
resBody: Record<'server' | 'db' | 'storage', 'ok'>;
};
}>;
1,254 changes: 697 additions & 557 deletions server/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"seed": "node -r esbuild-register prisma/seed.ts"
},
"dependencies": {
"@aws-sdk/client-cognito-identity-provider": "^3.606.0",
"@aws-sdk/client-s3": "^3.569.0",
"@aws-sdk/s3-request-presigner": "^3.572.0",
"@fastify/cookie": "^9.3.1",
Expand All @@ -48,6 +47,7 @@
},
"devDependencies": {
"@aspida/axios": "^1.14.0",
"@aws-sdk/client-cognito-identity-provider": "^3.609.0",
"@types/busboy": "^1.5.4",
"@types/node": "^20.12.10",
"axios": "^1.6.8",
Expand Down
24 changes: 0 additions & 24 deletions server/service/cognito.ts

This file was deleted.

6 changes: 0 additions & 6 deletions server/service/envValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ dotenv.config();
const SERVER_PORT = +z.string().regex(/^\d+$/).parse(process.env.SERVER_PORT);
const API_BASE_PATH = z.string().startsWith('/').parse(process.env.NEXT_PUBLIC_API_BASE_PATH);
const COGNITO_POOL_ENDPOINT = z.string().parse(process.env.NEXT_PUBLIC_COGNITO_POOL_ENDPOINT);
const COGNITO_ACCESS_KEY = z.string().parse(process.env.COGNITO_ACCESS_KEY);
const COGNITO_SECRET_KEY = z.string().parse(process.env.COGNITO_SECRET_KEY);
const COGNITO_REGION = z.string().parse(process.env.COGNITO_REGION);
const COGNITO_USER_POOL_ID = z.string().parse(process.env.COGNITO_USER_POOL_ID);
const COGNITO_USER_POOL_CLIENT_ID = z.string().parse(process.env.COGNITO_USER_POOL_CLIENT_ID);
const S3_ENDPOINT = z.string().parse(process.env.S3_ENDPOINT ?? '');
Expand All @@ -20,10 +17,7 @@ const S3_REGION = z.string().parse(process.env.S3_REGION ?? '');

export {
API_BASE_PATH,
COGNITO_ACCESS_KEY,
COGNITO_POOL_ENDPOINT,
COGNITO_REGION,
COGNITO_SECRET_KEY,
COGNITO_USER_POOL_CLIENT_ID,
COGNITO_USER_POOL_ID,
S3_ACCESS_KEY,
Expand Down
2 changes: 1 addition & 1 deletion server/tests/api/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import {
import api from 'api/$api';
import assert from 'assert';
import axios from 'axios';
import { cognitoClient } from 'service/cognito';
import { COOKIE_NAME } from 'service/constants';
import {
API_BASE_PATH,
COGNITO_USER_POOL_CLIENT_ID,
COGNITO_USER_POOL_ID,
SERVER_PORT,
} from 'service/envValues';
import { cognitoClient } from 'tests/api/cognito';

const baseURL = `http://127.0.0.1:${SERVER_PORT}${API_BASE_PATH}`;

Expand Down
8 changes: 8 additions & 0 deletions server/tests/api/cognito.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CognitoIdentityProviderClient } from '@aws-sdk/client-cognito-identity-provider';
import { COGNITO_POOL_ENDPOINT } from 'service/envValues';

export const cognitoClient = new CognitoIdentityProviderClient({
endpoint: COGNITO_POOL_ENDPOINT,
region: 'ap-northeast-1',
credentials: { accessKeyId: 'cognito-access-key', secretAccessKey: 'cognito-secret-key' },
});

0 comments on commit 5d481d9

Please sign in to comment.