This commit is contained in:
dahyeon committed 2026-04-25 12:43:12 -07:00
1 parent f7ee34da4f
commit b7127b59af
9 files changed
+967 -9

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
# Cloudflare Pages 배포
## 최초 1회 준비
```bash
pnpm --filter web pages:login
pnpm --filter web exec wrangler pages project create lolympus --production-branch main
```
프로젝트명을 바꾸려면 배포 시 `CF_PAGES_PROJECT_NAME` 환경변수로 지정한다.
## 환경 파일
Vite는 빌드 시점에 환경변수를 번들에 포함한다.
```bash
cp apps/web/.env.test.example apps/web/.env.test
cp apps/web/.env.production.example apps/web/.env.production
```
각 파일에서 API URL, community ID, MSAL 설정을 실제 값으로 채운다.
## 배포
```bash
pnpm deploy:web:test
pnpm deploy:web:prod
```
- `test`: `vite build --mode test` 후 Cloudflare Pages `test` preview branch로 배포
- `prod`: `vite build --mode production` 후 Cloudflare Pages production으로 배포
기본 Cloudflare Pages project name은 `lolympus`다.
```bash
CF_PAGES_PROJECT_NAME=lolympus-web pnpm deploy:web:prod
CF_PAGES_TEST_BRANCH=staging pnpm deploy:web:test
```
## SPA / 캐시
- `apps/web/public/_redirects`: React Router 경로 새로고침을 `/index.html`로 fallback
- `apps/web/public/_headers`: fingerprinted `/assets/*`는 1년 immutable 캐시, `index.html`은 no-cache
+7
View File
@@ -0,0 +1,7 @@
VITE_API_BASE_URL=https://lolympus-test.dahyeon.us
VITE_DEFAULT_COMMUNITY_ID=69ebe0adf627c11be2f020a1
VITE_MSAL_CLIENT_ID=15fb5a20-47e0-44fa-9a41-b50ca9d0e7e3
VITE_MSAL_AUTHORITY=https://login.microsoftonline.com/5ef88004-e953-4b04-93db-64bbf49c6863
VITE_MSAL_API_SCOPE=api://15fb5a20-47e0-44fa-9a41-b50ca9d0e7e3/lolympus-tournament-support-dev
VITE_MSAL_REDIRECT_URI=http://localhost:5173/auth/callback
+6
View File
@@ -0,0 +1,6 @@
VITE_API_BASE_URL=https://lolympus-test.dahyeon.us
VITE_DEFAULT_COMMUNITY_ID=69ebe0adf627c11be2f020a1
VITE_MSAL_CLIENT_ID=15fb5a20-47e0-44fa-9a41-b50ca9d0e7e3
VITE_MSAL_AUTHORITY=https://login.microsoftonline.com/5ef88004-e953-4b04-93db-64bbf49c6863
VITE_MSAL_API_SCOPE=api://15fb5a20-47e0-44fa-9a41-b50ca9d0e7e3/lolympus-tournament-support-dev
VITE_MSAL_REDIRECT_URI=http://localhost:5173/auth/callback
+8 -1
View File
@@ -6,6 +6,12 @@
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"build:test": "tsc -b && vite build --mode test",
"build:prod": "tsc -b && vite build --mode production",
"deploy:test": "node ../../scripts/deploy-cloudflare-pages.mjs test",
"deploy:prod": "node ../../scripts/deploy-cloudflare-pages.mjs prod",
"pages:login": "wrangler login",
"pages:whoami": "wrangler whoami",
"lint": "eslint .",
"preview": "vite preview"
},
@@ -33,6 +39,7 @@
"tailwindcss": "^4.2.2",
"typescript": "~6.0.2",
"typescript-eslint": "^8.58.0",
"vite": "^8.0.4"
"vite": "^8.0.4",
"wrangler": "^4.85.0"
}
}
+9
View File
@@ -0,0 +1,9 @@
/*
X-Content-Type-Options: nosniff
Referrer-Policy: strict-origin-when-cross-origin
/assets/*
Cache-Control: public, max-age=31536000, immutable
/index.html
Cache-Control: no-cache
+1
View File
@@ -0,0 +1 @@
/* /index.html 200
+4
View File
@@ -10,6 +10,10 @@
"start:api": "pnpm --filter api start:prod",
"build:api": "pnpm --filter api build",
"dev:web": "pnpm --filter web dev",
"build:web:test": "pnpm --filter web build:test",
"build:web:prod": "pnpm --filter web build:prod",
"deploy:web:test": "node scripts/deploy-cloudflare-pages.mjs test",
"deploy:web:prod": "node scripts/deploy-cloudflare-pages.mjs prod",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
+780 -8
View File
File diff suppressed because it is too large. Load diff
+109
View File
@@ -0,0 +1,109 @@
import { spawnSync } from 'node:child_process';
import { existsSync, readFileSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const repoRoot = resolve(__dirname, '..');
const webDir = resolve(repoRoot, 'apps/web');
const target = process.argv[2];
if (target !== 'test' && target !== 'prod') {
console.error('Usage: node scripts/deploy-cloudflare-pages.mjs <test|prod>');
process.exit(1);
}
const viteMode = target === 'prod' ? 'production' : 'test';
const projectName =
process.env.CF_PAGES_PROJECT_NAME ??
process.env.CLOUDFLARE_PAGES_PROJECT_NAME ??
'lolympus';
const testBranch = process.env.CF_PAGES_TEST_BRANCH ?? 'test';
validateEnv(viteMode);
run('pnpm', ['--filter', 'web', 'run', `build:${target}`], repoRoot);
const deployArgs = [
'exec',
'wrangler',
'pages',
'deploy',
'dist',
'--project-name',
projectName,
];
if (target === 'test') {
deployArgs.push('--branch', testBranch);
}
run('pnpm', deployArgs, webDir);
function run(command, args, cwd) {
const result = spawnSync(command, args, {
cwd,
stdio: 'inherit',
shell: process.platform === 'win32',
});
if (result.status !== 0) {
process.exit(result.status ?? 1);
}
}
function validateEnv(mode) {
const fileEnv = [
'.env',
'.env.local',
`.env.${mode}`,
`.env.${mode}.local`,
].reduce((acc, fileName) => {
const envFile = resolve(webDir, fileName);
if (!existsSync(envFile)) return acc;
return { ...acc, ...parseEnvFile(envFile) };
}, {});
const requiredKeys = [
'VITE_API_BASE_URL',
'VITE_DEFAULT_COMMUNITY_ID',
'VITE_MSAL_CLIENT_ID',
'VITE_MSAL_AUTHORITY',
'VITE_MSAL_API_SCOPE',
'VITE_MSAL_REDIRECT_URI',
];
const missing = requiredKeys.filter((key) => {
const value = process.env[key] ?? fileEnv[key];
return !value || value.includes('<');
});
if (missing.length === 0) return;
console.error(
[
`Missing Cloudflare Pages ${mode} build env: ${missing.join(', ')}`,
`Create apps/web/.env.${mode}, apps/web/.env.${mode}.local, or export these variables before deploy.`,
`Use apps/web/.env.${mode}.example as a template.`,
].join('\n'),
);
process.exit(1);
}
function parseEnvFile(path) {
return Object.fromEntries(
readFileSync(path, 'utf8')
.split(/\r?\n/)
.map((line) => line.trim())
.filter((line) => line && !line.startsWith('#'))
.map((line) => {
const separatorIndex = line.indexOf('=');
if (separatorIndex === -1) return [line, ''];
const key = line.slice(0, separatorIndex).trim();
let value = line.slice(separatorIndex + 1).trim();
if (
(value.startsWith('"') && value.endsWith('"')) ||
(value.startsWith("'") && value.endsWith("'"))
) {
value = value.slice(1, -1);
}
return [key, value];
}),
);
}