Compare commits

...

10 Commits

Author SHA1 Message Date
2625ed0131 frontend/Dockerfile — Added ARG + ENV for build-time variables
docker-compose.yml — Added build.args to pass the values into the Docker build:
2026-02-19 12:42:49 +09:00
1400c3f23e i use dokploy to deploy. so i guess we dont need use PORT in docker-compose.yml 2026-02-19 12:24:42 +09:00
92e1d41f8d aaa 2026-02-19 12:20:26 +09:00
827b0bb6d5 Change the port mapping to ${FRONTEND_PORT}:3000 so the container always uses 3000 internally but maps to a different host port. 2026-02-19 12:17:18 +09:00
c32d5c9977 5000 not 3000 2026-02-19 12:09:31 +09:00
55a2bc8281 fix dockerfile in backend 2026-02-19 11:42:54 +09:00
00194f3826 updated docker-compose.yml 2026-02-19 11:26:23 +09:00
5c021511c4 .env.for-docker-compose 2026-02-19 11:19:35 +09:00
366a11814c try use docker 2026-02-19 11:10:32 +09:00
3d2de67d1e FullStack-Blog-Nestjs-Nextjs-Postgres 2026-02-19 05:24:02 +09:00
89 changed files with 305 additions and 173 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

49
.env.for-docker-compose Normal file
View File

@@ -0,0 +1,49 @@
# Backend (NestJS)
NODE_ENV=production
HOST=0.0.0.0
BACKEND_PORT=3001
APP_URL=
DB_HOST=
DB_PORT=
DB_USER=
DB_PASSWORD=
DB_NAME=
DB_SSL=
JWT_ACCESS_SECRET=change-me-access-secret-at-least-32-chars
JWT_REFRESH_SECRET=change-me-refresh-secret-at-least-32-chars
JWT_ACCESS_EXPIRES_IN=15m
JWT_REFRESH_EXPIRES_IN=7d
MAGIC_LINK_TTL_MINUTES=20
PASSWORD_RESET_TTL_MINUTES=30
COOKIE_SECURE=false
COOKIE_DOMAIN=
SMTP_HOST=
SMTP_PORT=
SMTP_USER=
SMTP_PASS=
MAIL_FROM=
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_CALLBACK_URL=
FRONTEND_URL=
# Frontend (Next.js)
FRONTEND_PORT=3000
NEXT_PUBLIC_API_URL=http://localhost:3001
UPLOAD_R2_WORKER_API=
R2_UPLOAD_API_KEY=
# Frontend (Next.js)
FRONTEND_PORT=3000
NEXT_PUBLIC_API_URL=
UPLOAD_R2_WORKER_API=
R2_UPLOAD_API_KEY=

99
.gitignore vendored
View File

@@ -1,100 +1 @@
# -----------------------------
# Dependencies
# -----------------------------
node_modules/
jspm_packages/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# -----------------------------
# Build Output
# -----------------------------
dist/
build/
coverage/
.nyc_output/
# TypeScript
*.tsbuildinfo
# -----------------------------
# Environment Variables
# -----------------------------
.env .env
.env.*
!.env.example
# -----------------------------
# Logs
# -----------------------------
logs/
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
# -----------------------------
# OS Files
# -----------------------------
.DS_Store
Thumbs.db
# -----------------------------
# IDE / Editor
# -----------------------------
.vscode/
!.vscode/extensions.json
.idea/
*.swp
*.swo
# -----------------------------
# Testing
# -----------------------------
/jest-cache/
coverage/
# -----------------------------
# Misc
# -----------------------------
tmp/
temp/
.cache/
# -----------------------------
# Docker (optional)
# -----------------------------
docker-compose.override.yml
# -----------------------------
# Package Managers
# -----------------------------
.pnp/
.pnp.js
# -----------------------------
# Nest CLI
# -----------------------------
nest-cli.json.lock
# -----------------------------
# Firebase / Serverless (optional)
# -----------------------------
.firebase/
.serverless/
# -----------------------------
# Mac
# -----------------------------
.AppleDouble
.LSOverride
*.sqlite
*.sqlite3

View File

@@ -1,31 +1,6 @@
<p align="center">
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a>
</p>
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456 # BackEnd
[circleci-url]: https://circleci.com/gh/nestjs/nest ### init
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
<p align="center">
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg" alt="Donate us"/></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow" alt="Follow us on Twitter"></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->
## Description
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
## Project init
```bash ```bash
# 1. Set up PostgreSQL and fill in .env # 1. Set up PostgreSQL and fill in .env
@@ -42,7 +17,7 @@ npm run seed:admin
npm run seed:posts npm run seed:posts
``` ```
## Compile and run the project ### Compile and run
```bash ```bash
# development # development
@@ -55,7 +30,7 @@ $ npm run start:dev
$ npm run start:prod $ npm run start:prod
``` ```
## Run tests ### Run tests
```bash ```bash
# unit tests # unit tests
@@ -68,4 +43,19 @@ $ npm run test:e2e
$ npm run test:cov $ npm run test:cov
``` ```
# FrontEnd
```bash
# development
$ npm run dev
# build,deploy
$ npm run build
```
# Deploy
```
docker compose down --volumes
docker compose build --no-cache
docker compose up --force-recreate
```

19
backend/.dockerignore Normal file
View File

@@ -0,0 +1,19 @@
# Versioning and metadata
.git
.gitignore
.dockerignore
# Build dependencies
dist
node_modules
coverage
# Environment (contains sensitive data)
.env
# Files not required for production
.editorconfig
Dockerfile
README.md
.eslintrc.js
nodemon.json

View File

@@ -1,7 +1,7 @@
NODE_ENV=development NODE_ENV=development
HOST=0.0.0.0 HOST=0.0.0.0
PORT=3000 PORT=5001
APP_URL=http://localhost:3000 APP_URL=http://localhost:5001
# Database # Database
DB_HOST=localhost DB_HOST=localhost
@@ -35,4 +35,7 @@ SMTP_PASS=
# Google OAuth # Google OAuth
GOOGLE_CLIENT_ID= GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET= GOOGLE_CLIENT_SECRET=
GOOGLE_CALLBACK_URL=http://localhost:3000/auth/google/callback GOOGLE_CALLBACK_URL=http://localhost:5000/auth/google/callback
FRONTEND_URL=http://localhost:5000

100
backend/.gitignore vendored Normal file
View File

@@ -0,0 +1,100 @@
# -----------------------------
# Dependencies
# -----------------------------
node_modules/
jspm_packages/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# -----------------------------
# Build Output
# -----------------------------
dist/
build/
coverage/
.nyc_output/
# TypeScript
*.tsbuildinfo
# -----------------------------
# Environment Variables
# -----------------------------
.env
.env.*
!.env.example
# -----------------------------
# Logs
# -----------------------------
logs/
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
# -----------------------------
# OS Files
# -----------------------------
.DS_Store
Thumbs.db
# -----------------------------
# IDE / Editor
# -----------------------------
.vscode/
!.vscode/extensions.json
.idea/
*.swp
*.swo
# -----------------------------
# Testing
# -----------------------------
/jest-cache/
coverage/
# -----------------------------
# Misc
# -----------------------------
tmp/
temp/
.cache/
# -----------------------------
# Docker (optional)
# -----------------------------
docker-compose.override.yml
# -----------------------------
# Package Managers
# -----------------------------
.pnp/
.pnp.js
# -----------------------------
# Nest CLI
# -----------------------------
nest-cli.json.lock
# -----------------------------
# Firebase / Serverless (optional)
# -----------------------------
.firebase/
.serverless/
# -----------------------------
# Mac
# -----------------------------
.AppleDouble
.LSOverride
*.sqlite
*.sqlite3

14
backend/Dockerfile Normal file
View File

@@ -0,0 +1,14 @@
FROM node:20-alpine AS base
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM node:20-alpine AS production
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY --from=base /app/dist ./dist
EXPOSE 3001
CMD ["node", "dist/src/main.js"]

View File

@@ -22,7 +22,5 @@
"paths": { "paths": {
"@/*": ["src/*"] "@/*": ["src/*"]
} }
}, }
"include": ["src/**/*", "scripts/**/*"],
"exclude": ["node_modules", "dist", "test"]
} }

52
docker-compose.yml Normal file
View File

@@ -0,0 +1,52 @@
version: '3.9'
services:
backend:
build:
context: ./backend
dockerfile: Dockerfile
restart: unless-stopped
environment:
NODE_ENV: ${NODE_ENV}
HOST: ${HOST}
PORT: ${BACKEND_PORT}
APP_URL: ${APP_URL}
DB_HOST: ${DB_HOST}
DB_PORT: ${DB_PORT}
DB_USER: ${DB_USER}
DB_PASSWORD: ${DB_PASSWORD}
DB_NAME: ${DB_NAME}
DB_SSL: ${DB_SSL}
JWT_ACCESS_SECRET: ${JWT_ACCESS_SECRET}
JWT_REFRESH_SECRET: ${JWT_REFRESH_SECRET}
JWT_ACCESS_EXPIRES_IN: ${JWT_ACCESS_EXPIRES_IN}
JWT_REFRESH_EXPIRES_IN: ${JWT_REFRESH_EXPIRES_IN}
MAGIC_LINK_TTL_MINUTES: ${MAGIC_LINK_TTL_MINUTES}
PASSWORD_RESET_TTL_MINUTES: ${PASSWORD_RESET_TTL_MINUTES}
COOKIE_SECURE: ${COOKIE_SECURE}
COOKIE_DOMAIN: ${COOKIE_DOMAIN}
MAIL_FROM: ${MAIL_FROM}
SMTP_HOST: ${SMTP_HOST}
SMTP_PORT: ${SMTP_PORT}
SMTP_USER: ${SMTP_USER}
SMTP_PASS: ${SMTP_PASS}
GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID}
GOOGLE_CLIENT_SECRET: ${GOOGLE_CLIENT_SECRET}
GOOGLE_CALLBACK_URL: ${GOOGLE_CALLBACK_URL}
FRONTEND_URL: ${FRONTEND_URL}
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
args:
NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL}
UPLOAD_R2_WORKER_API: ${UPLOAD_R2_WORKER_API}
R2_UPLOAD_API_KEY: ${R2_UPLOAD_API_KEY}
restart: unless-stopped
environment:
NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL}
UPLOAD_R2_WORKER_API: ${UPLOAD_R2_WORKER_API}
R2_UPLOAD_API_KEY: ${R2_UPLOAD_API_KEY}
depends_on:
- backend

13
frontend/.dockerignore Normal file
View File

@@ -0,0 +1,13 @@
node_modules
npm-debug.log
Dockerfile*
docker-compose*
.dockerignore
.git
.gitignore
README.md
LICENSE
.vscode
.next
*.swp
/scripts

4
frontend/.env.example Normal file
View File

@@ -0,0 +1,4 @@
NEXT_PUBLIC_API_URL=http://localhost:5001
UPLOAD_R2_WORKER_API=***.workers.dev
R2_UPLOAD_API_KEY=***

2
frontend/.gitignore vendored
View File

@@ -31,7 +31,7 @@ yarn-error.log*
.pnpm-debug.log* .pnpm-debug.log*
# env files (can opt-in for committing if needed) # env files (can opt-in for committing if needed)
.env* .env
# vercel # vercel
.vercel .vercel

25
frontend/Dockerfile Normal file
View File

@@ -0,0 +1,25 @@
FROM node:20-alpine AS base
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
# Build args for NEXT_PUBLIC_ vars (baked in at build time)
ARG NEXT_PUBLIC_API_URL
ARG UPLOAD_R2_WORKER_API
ARG R2_UPLOAD_API_KEY
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
ENV UPLOAD_R2_WORKER_API=$UPLOAD_R2_WORKER_API
ENV R2_UPLOAD_API_KEY=$R2_UPLOAD_API_KEY
RUN npm run build
FROM node:20-alpine AS production
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY --from=base /app/.next ./.next
COPY --from=base /app/public ./public
EXPOSE 3000
CMD ["npm", "start"]

View File

@@ -1,36 +0,0 @@
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
## Getting Started
First, run the development server:
```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
## Learn More
To learn more about Next.js, take a look at the following resources:
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
## Deploy on Vercel
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.