Skip to content

Conversation

@mashharuki
Copy link
Collaborator

This pull request introduces Docker support for the backend, updates the backend to be compatible with Google Cloud Run, and improves the development workflow. It also includes minor updates to the frontend service worker. Below is a breakdown of the most important changes:

Backend Dockerization and Cloud Run Compatibility

  • Added a .dockerignore file to exclude unnecessary files like node_modules, .env, and .git from the Docker build context (pkgs/backend/.dockerignore).
  • Created a Dockerfile for building and running the backend using Node.js 20, including dependency installation and application build steps (pkgs/backend/Dockerfile).
  • Updated the backend to use the PORT environment variable for compatibility with Google Cloud Run (pkgs/backend/src/index.ts).

Documentation Enhancements

  • Added a detailed README.md file with instructions for local development, Docker usage, and deployment to Google Cloud Run (pkgs/backend/README.md).

Development Workflow Improvements

  • Added new npm scripts for building, running, and managing the backend with Docker (pkgs/backend/package.json).
  • Enabled CORS in the backend to allow cross-origin requests (pkgs/backend/src/index.ts).
  • Updated tsconfig.json to specify the output directory as dist and include all files in the src folder (pkgs/backend/tsconfig.json).

Frontend Updates

  • Updated the service worker file to reflect new asset revisions, ensuring the latest versions of static files are served (pkgs/frontend/public/sw.js).

@mashharuki mashharuki requested a review from Copilot May 21, 2025 09:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds Docker support and Cloud Run compatibility for the backend, enhances local development workflows, and updates the frontend service worker with new asset revisions.

  • Dockerizes the backend with a new Dockerfile and .dockerignore
  • Updates TypeScript and npm scripts to build, run, and deploy on Cloud Run
  • Enables CORS and environment-based port configuration in the backend
  • Adds detailed README for local development, Docker, and Cloud Run deployment
  • Refreshes asset hashes in the frontend service worker

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
pkgs/frontend/public/sw.js Swapped loader variable names and updated static asset revisions
pkgs/backend/tsconfig.json Set "outDir": "dist" and broadened "include" to src/**/*
pkgs/backend/src/index.ts Added CORS middleware and made port configurable via PORT
pkgs/backend/package.json Added build, start, docker:build, and docker:run scripts
pkgs/backend/README.md New documentation for local, Docker, and Cloud Run workflows
pkgs/backend/Dockerfile Dockerfile for building and running the backend
pkgs/backend/.dockerignore Files to exclude from Docker build context
Comments suppressed due to low confidence (1)

pkgs/backend/src/index.ts:21

  • [nitpick] This log runs before the server actually listens; consider removing or moving it after serve(...) to avoid confusion.
console.log("Server is running");

Comment on lines +24 to +26
app.use(
cors({
origin: ["*"],
Copy link

Copilot AI May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a wildcard origin (*) with credentials: true is disallowed by browsers; either specify explicit origins or disable credentials.

Suggested change
app.use(
cors({
origin: ["*"],
const allowedOrigins = process.env.CORS_ALLOWED_ORIGINS
? process.env.CORS_ALLOWED_ORIGINS.split(",")
: [];
app.use(
cors({
origin: allowedOrigins,

Copilot uses AI. Check for mistakes.
"dev": "tsx ./src/index.ts"
"dev": "tsx ./src/index.ts",
"build": "tsc",
"start": "node --experimental-modules --es-module-specifier-resolution=node ./dist/index.js",
Copy link

Copilot AI May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Node.js 20 supports ES modules natively; you can simplify the start script to node ./dist/index.js and remove experimental flags.

Suggested change
"start": "node --experimental-modules --es-module-specifier-resolution=node ./dist/index.js",
"start": "node ./dist/index.js",

Copilot uses AI. Check for mistakes.
docker build -t backend-api .

# ローカルでコンテナを実行
docker run -p 8080:8080 --env-file .env backend-api
Copy link

Copilot AI May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README maps port 8080, but the app and Dockerfile use port 4021; update one to keep them consistent.

Suggested change
docker run -p 8080:8080 --env-file .env backend-api
docker run -p 4021:4021 --env-file .env backend-api

Copilot uses AI. Check for mistakes.
RUN pnpm install

# Install @types/node for TypeScript compilation
RUN pnpm add -D @types/node
Copy link

Copilot AI May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Installing @types/node inside the Dockerfile alters lockfiles; it's better to declare dev dependencies in package.json for consistency.

Copilot uses AI. Check for mistakes.
@mashharuki mashharuki merged commit 32fc805 into main May 21, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant