Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #28 from nekochans/feature/issue27/add-access-cont…
Browse files Browse the repository at this point in the history
…rol-allow-origin

CORSの設定が動作しないので Access-Control-Allow-Origin を追加
  • Loading branch information
keitakn authored Jan 15, 2023
2 parents 1c0b5ca + eba09db commit c5af084
Show file tree
Hide file tree
Showing 11 changed files with 766 additions and 459 deletions.
1,169 changes: 732 additions & 437 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
"version": "0.0.0",
"devDependencies": {
"@cloudflare/workers-types": "^4.20221111.1",
"@types/jest": "^29.2.4",
"@types/prettier": "^2.7.1",
"@typescript-eslint/eslint-plugin": "^5.46.1",
"eslint": "^8.30.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-standard-with-typescript": "^24.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^27.1.7",
"eslint-plugin-n": "^15.6.0",
"@types/jest": "^29.2.5",
"@types/prettier": "^2.7.2",
"@typescript-eslint/eslint-plugin": "^5.48.1",
"eslint": "^8.32.0",
"eslint-config-prettier": "^8.6.0",
"eslint-config-standard-with-typescript": "^27.0.1",
"eslint-plugin-import": "^2.27.4",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-n": "^15.6.1",
"eslint-plugin-promise": "^6.1.1",
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.3.1",
"msw": "^0.49.2",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.1",
"ts-jest": "^29.0.3",
"prettier": "^2.8.3",
"ts-jest": "^29.0.5",
"ts-node": "^10.9.1",
"typescript": "^4.9.4",
"whatwg-fetch": "^3.6.2",
"wrangler": "2.6.2"
"wrangler": "2.7.1"
},
"private": true,
"scripts": {
Expand All @@ -40,7 +40,7 @@
},
"dependencies": {
"@honojs/sentry": "^0.0.5",
"hono": "^2.6.2",
"hono": "^2.7.2",
"zod": "^3.20.2"
}
}
2 changes: 1 addition & 1 deletion src/api/isAcceptableCatImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const isAcceptableCatImageNotAcceptableReasons = [
] as const;

export type IsAcceptableCatImageNotAcceptableReason =
typeof isAcceptableCatImageNotAcceptableReasons[number];
(typeof isAcceptableCatImageNotAcceptableReasons)[number];

export type IsAcceptableCatImageResponse = {
isAcceptableCatImage: boolean;
Expand Down
3 changes: 0 additions & 3 deletions src/api/uploadLgtmImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ export const uploadLgtmImage = async (

const response = await fetch(`${dto.apiBaseUrl}/lgtm-images`, options);

console.log(response.status);
console.log(`${dto.apiBaseUrl}/lgtm-images`);

if (response.status !== httpStatusCode.accepted) {
const requestIds = mightExtractRequestIds(response);

Expand Down
1 change: 1 addition & 0 deletions src/handlers/handleCatImageValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const handleCatImageValidation = async (dto: Dto): Promise<Response> => {

const headers: ResponseHeader = {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
};

if (isAcceptableCatImageResult.value.xRequestId != null) {
Expand Down
1 change: 1 addition & 0 deletions src/handlers/handleFetchLgtmImagesInRandom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const handleFetchLgtmImagesInRandom = async (

const headers: ResponseHeader = {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
};

if (fetchLgtmImagesResult.value.xRequestId != null) {
Expand Down
1 change: 1 addition & 0 deletions src/handlers/handleFetchLgtmImagesInRecentlyCreated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const handleFetchLgtmImagesInRecentlyCreated = async (

const headers: ResponseHeader = {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
};

if (fetchLgtmImagesResult.value.xRequestId != null) {
Expand Down
1 change: 1 addition & 0 deletions src/handlers/handleUploadLgtmImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const handleUploadLgtmImage = async (dto: Dto): Promise<Response> => {

const headers: ResponseHeader = {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
};

if (uploadLgtmImageResult.value.xRequestId != null) {
Expand Down
16 changes: 13 additions & 3 deletions src/handlers/handlerResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ import { InvalidParams } from '../validator';

export type ResponseHeader = {
'Content-Type': 'application/json';
'Access-Control-Allow-Origin': string;
'X-Request-Id'?: string;
'X-Lambda-Request-Id'?: string;
};

export const createSuccessResponse = (
body: unknown,
statusCode: HttpStatusCode = httpStatusCode.ok,
headers: ResponseHeader = { 'Content-Type': 'application/json' }
headers: ResponseHeader = {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
}
): Response => {
const jsonBody = JSON.stringify(body);

Expand All @@ -34,12 +38,18 @@ export type ValidationProblemDetails = {
export const createErrorResponse = (
problemDetails: ProblemDetails,
statusCode: HttpStatusCode = httpStatusCode.internalServerError,
headers: ResponseHeader = { 'Content-Type': 'application/json' }
headers: ResponseHeader = {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
}
): Response => createSuccessResponse(problemDetails, statusCode, headers);

export const createValidationErrorResponse = (
invalidParams: InvalidParams,
headers: ResponseHeader = { 'Content-Type': 'application/json' }
headers: ResponseHeader = {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
}
): Response => {
const validationProblemDetails: ValidationProblemDetails = {
title: 'unprocessable entity',
Expand Down
3 changes: 2 additions & 1 deletion src/httpStatusCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export const httpStatusCode = {
serviceUnavailable: 503,
} as const;

export type HttpStatusCode = typeof httpStatusCode[keyof typeof httpStatusCode];
export type HttpStatusCode =
(typeof httpStatusCode)[keyof typeof httpStatusCode];
2 changes: 1 addition & 1 deletion src/lgtmImage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const acceptedTypesImageExtensions = ['.png', '.jpg', '.jpeg'] as const;

export type AcceptedTypesImageExtension =
typeof acceptedTypesImageExtensions[number];
(typeof acceptedTypesImageExtensions)[number];

type LgtmImageUrl = `https://${string}`;

Expand Down

0 comments on commit c5af084

Please sign in to comment.