Initial commit: add FastAPI MVP (모프) and existing web app

Includes FastAPI+Jinja2+HTMX+SQLite implementation with seed categories, plus deployment templates.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dsyoon
2026-02-16 17:17:22 +09:00
commit 27540269b7
37 changed files with 3246 additions and 0 deletions

View File

@@ -0,0 +1,149 @@
# 서버에서 바로 실행 배포 가이드 (도커 없이)
목표: `prompt.ncue.net` → (Nginx 리버스프록시) → `localhost:3000`(Next.js)
## 1) 서버 준비
- Node.js LTS 설치(권장 20.x 이상)
- PostgreSQL은 외부(`ncue.net/all_prompt`) 사용
- `git`, `build-essential`(일부 패키지 빌드 필요 시) 설치
## 2) 코드 배포(예시)
```bash
cd /opt
sudo git clone <YOUR_REPO_URL> all-prompt
cd /opt/all-prompt/apps/web
sudo npm ci
```
## 3) 환경변수 설정
`.env`를 생성한다(예: `/opt/all-prompt/apps/web/.env`).
```bash
DATABASE_URL="postgresql://ncue:<PASSWORD>@ncue.net:5432/all_prompt?schema=public"
NEXT_PUBLIC_SITE_URL="https://prompt.ncue.net"
NODE_ENV="production"
PORT=3000
```
## 4) DB 스키마 적용(1회)
> 이미 DB에 테이블이 있다면 생략 가능.
### A안(권장): psql로 DDL 적용
```bash
export PGPASSWORD="<PASSWORD>"
psql -h ncue.net -U ncue -d all_prompt -f db/schema.sql
```
### B안: Prisma db push(DDL 대신 Prisma 기준)
```bash
npm run prisma:generate
npm run db:push
```
## 5) 시드 데이터(1회)
```bash
npm run db:seed
```
## 6) 빌드/실행
```bash
npm run build
npm run start
```
이제 `http://localhost:3000`에서 동작해야 한다.
## 7) systemd로 상시 실행
### 7.1 서비스 유저(권장)
```bash
sudo useradd -r -s /usr/sbin/nologin allprompt || true
sudo chown -R allprompt:allprompt /opt/all-prompt
```
### 7.2 유닛 파일 생성
`/etc/systemd/system/allprompt-web.service`
```ini
[Unit]
Description=all prompt (모프) Next.js web
After=network.target
[Service]
Type=simple
User=allprompt
WorkingDirectory=/opt/all-prompt/apps/web
Environment=NODE_ENV=production
Environment=PORT=3000
EnvironmentFile=/opt/all-prompt/apps/web/.env
ExecStart=/usr/bin/npm run start
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target
```
적용:
```bash
sudo systemctl daemon-reload
sudo systemctl enable --now allprompt-web
sudo systemctl status allprompt-web
```
## 8) Nginx 리버스프록시로 prompt.ncue.net 연결
### 8.1 Nginx 설치 및 서버블록
`/etc/nginx/sites-available/prompt.ncue.net`
```nginx
server {
listen 80;
server_name prompt.ncue.net;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
```
활성화:
```bash
sudo ln -s /etc/nginx/sites-available/prompt.ncue.net /etc/nginx/sites-enabled/prompt.ncue.net
sudo nginx -t && sudo systemctl reload nginx
```
### 8.2 HTTPS(권장): Lets Encrypt
```bash
sudo apt-get update
sudo apt-get install -y certbot python3-certbot-nginx
sudo certbot --nginx -d prompt.ncue.net
```
## 9) 배포 후 확인
- `https://prompt.ncue.net/api/health`
- `https://prompt.ncue.net/entities`
- `https://prompt.ncue.net/prompts`