Skip to content

Commit d01d51d

Browse files
committed
chore: setting deploy workflows
1 parent 2a6f9a6 commit d01d51d

11 files changed

Lines changed: 199 additions & 19 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Deploy to GitHub Pages
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
# GitHub Pages 권한 설정
10+
permissions:
11+
contents: read
12+
pages: write
13+
id-token: write
14+
15+
# 동시 배포 방지
16+
concurrency:
17+
group: "pages"
18+
cancel-in-progress: false
19+
20+
jobs:
21+
# 빌드 잡
22+
build:
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
29+
- name: Setup Node.js
30+
uses: actions/setup-node@v4
31+
with:
32+
node-version: '20'
33+
34+
- name: Setup pnpm
35+
uses: pnpm/action-setup@v4
36+
with:
37+
run_install: false
38+
39+
- name: Get pnpm store directory
40+
shell: bash
41+
run: |
42+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
43+
44+
- name: Setup pnpm cache
45+
uses: actions/cache@v4
46+
with:
47+
path: ${{ env.STORE_PATH }}
48+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
49+
restore-keys: |
50+
${{ runner.os }}-pnpm-store-
51+
52+
- name: Install dependencies
53+
run: pnpm install --frozen-lockfile
54+
55+
- name: Lint
56+
run: pnpm lint
57+
58+
- name: Build
59+
run: pnpm build
60+
env:
61+
# GitHub Pages 하위 경로를 위한 base 설정
62+
VITE_BASE_URL: /${{ github.event.repository.name }}/
63+
64+
- name: Setup Pages
65+
uses: actions/configure-pages@v5
66+
67+
- name: Upload artifact
68+
uses: actions/upload-pages-artifact@v3
69+
with:
70+
path: ./dist
71+
72+
# 배포 잡 (main 브랜치에서만)
73+
deploy:
74+
if: github.ref == 'refs/heads/main'
75+
environment:
76+
name: github-pages
77+
url: ${{ steps.deployment.outputs.page_url }}
78+
runs-on: ubuntu-latest
79+
needs: build
80+
81+
steps:
82+
- name: Deploy to GitHub Pages
83+
id: deployment
84+
uses: actions/deploy-pages@v4

index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>Chapter 2-3. 관심사 분리와 폴더구조</title>
88
<script src="https://cdn.tailwindcss.com"></script>
9+
10+
<!-- GitHub Pages SPA support -->
11+
<script>
12+
// Single Page Apps for GitHub Pages
13+
// https://github.com/rafgraph/spa-github-pages
14+
;(function (l) {
15+
if (l.search[1] === "/") {
16+
var decoded = l.search
17+
.slice(1)
18+
.split("&")
19+
.map(function (s) {
20+
return s.replace(/~and~/g, "&")
21+
})
22+
.join("?")
23+
window.history.replaceState(null, null, l.pathname.slice(0, -1) + decoded + l.hash)
24+
}
25+
})(window.location)
26+
</script>
927
</head>
1028
<body>
1129
<div id="root"></div>

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"private": true,
44
"version": "0.0.0",
55
"type": "module",
6+
"packageManager": "pnpm@9.0.0",
67
"scripts": {
78
"dev": "vite",
89
"build": "tsc -b && vite build",
@@ -14,7 +15,8 @@
1415
"dependencies": {
1516
"@tanstack/react-query": "^5.84.2",
1617
"react": "^19.1.1",
17-
"react-dom": "^19.1.1"
18+
"react-dom": "^19.1.1",
19+
"zustand": "^5.0.2"
1820
},
1921
"devDependencies": {
2022
"@eslint/js": "^9.33.0",

pnpm-lock.yaml

Lines changed: 28 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/404.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Posts Manager</title>
6+
<script>
7+
// GitHub Pages SPA redirect script
8+
// This script takes the current url and converts the path and query
9+
// string into just a query string, and then redirects the browser
10+
// to the new url with only a query string and hash fragment
11+
var segmentCount = 1 // number of path segments to keep (1 for GitHub Pages repo name)
12+
13+
var l = window.location
14+
l.replace(
15+
l.protocol +
16+
"//" +
17+
l.hostname +
18+
(l.port ? ":" + l.port : "") +
19+
l.pathname
20+
.split("/")
21+
.slice(0, 1 + segmentCount)
22+
.join("/") +
23+
"/?/" +
24+
l.pathname.slice(1).split("/").slice(segmentCount).join("/").replace(/&/g, "~and~") +
25+
(l.search ? "&" + l.search.slice(1).replace(/&/g, "~and~") : "") +
26+
l.hash,
27+
)
28+
</script>
29+
</head>
30+
<body></body>
31+
</html>

src/entities/comment/api/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
import { createApiUrl } from "@shared/lib"
12
import { Comment, NewComment } from "@entities/comment/model/types"
23

34
// Export hooks
45
export * from "./queries"
56
export * from "./mutations"
67

78
export const fetchComments = async (postId: number) => {
8-
const response = await fetch(`/api/comments/post/${postId}`)
9+
const response = await fetch(createApiUrl(`comments/post/${postId}`))
910
return response.json()
1011
}
1112

1213
export const addComment = async (comment: NewComment): Promise<Comment> => {
13-
const response = await fetch("/api/comments/add", {
14+
const response = await fetch(createApiUrl("comments/add"), {
1415
method: "POST",
1516
headers: { "Content-Type": "application/json" },
1617
body: JSON.stringify(comment),
@@ -19,7 +20,7 @@ export const addComment = async (comment: NewComment): Promise<Comment> => {
1920
}
2021

2122
export const updateComment = async (id: number, body: string): Promise<Comment> => {
22-
const response = await fetch(`/api/comments/${id}`, {
23+
const response = await fetch(createApiUrl(`comments/${id}`), {
2324
method: "PUT",
2425
headers: { "Content-Type": "application/json" },
2526
body: JSON.stringify({ body }),
@@ -28,14 +29,14 @@ export const updateComment = async (id: number, body: string): Promise<Comment>
2829
}
2930

3031
export const deleteComment = async (id: number): Promise<void> => {
31-
await fetch(`/api/comments/${id}`, {
32+
await fetch(createApiUrl(`comments/${id}`), {
3233
method: "DELETE",
3334
})
3435
}
3536

3637
// 버그 수정: API에서 반환된 데이터를 그대로 사용하도록 수정
3738
export const likeComment = async (id: number, currentLikes: number): Promise<Comment> => {
38-
const response = await fetch(`/api/comments/${id}`, {
39+
const response = await fetch(createApiUrl(`comments/${id}`), {
3940
method: "PATCH",
4041
headers: { "Content-Type": "application/json" },
4142
body: JSON.stringify({ likes: currentLikes + 1 }),

src/entities/post/api/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Post, PostsApiResponse, NewPost } from "@entities/post/model/types"
2-
import { createURLParams } from "@shared/lib"
2+
import { createURLParams, createApiUrl } from "@shared/lib"
33

44
// Export hooks
55
export * from "./queries"
@@ -16,7 +16,7 @@ export const fetchPosts = async (
1616
skip,
1717
...(sortBy && sortBy !== "none" ? { sortBy, order: sortOrder } : {}),
1818
})
19-
const response = await fetch(`/api/posts?${query}`)
19+
const response = await fetch(createApiUrl(`posts?${query}`))
2020
return response.json()
2121
}
2222

@@ -33,7 +33,7 @@ export const searchPosts = async (
3333
skip,
3434
...(sortBy && sortBy !== "none" ? { sortBy, order: sortOrder } : {}),
3535
})
36-
const response = await fetch(`/api/posts/search?${queryString}`)
36+
const response = await fetch(createApiUrl(`posts/search?${queryString}`))
3737
return response.json()
3838
}
3939

@@ -49,12 +49,12 @@ export const fetchPostsByTag = async (
4949
skip,
5050
...(sortBy && sortBy !== "none" ? { sortBy, order: sortOrder } : {}),
5151
})
52-
const response = await fetch(`/api/posts/tag/${encodeURIComponent(tag)}?${queryString}`)
52+
const response = await fetch(createApiUrl(`posts/tag/${encodeURIComponent(tag)}?${queryString}`))
5353
return response.json()
5454
}
5555

5656
export const addPost = async (post: NewPost): Promise<Post> => {
57-
const response = await fetch("/api/posts/add", {
57+
const response = await fetch(createApiUrl("posts/add"), {
5858
method: "POST",
5959
headers: { "Content-Type": "application/json" },
6060
body: JSON.stringify(post),
@@ -63,7 +63,7 @@ export const addPost = async (post: NewPost): Promise<Post> => {
6363
}
6464

6565
export const updatePost = async (id: number, post: Partial<Post>): Promise<Post> => {
66-
const response = await fetch(`/api/posts/${id}`, {
66+
const response = await fetch(createApiUrl(`posts/${id}`), {
6767
method: "PUT",
6868
headers: { "Content-Type": "application/json" },
6969
body: JSON.stringify(post),
@@ -72,12 +72,12 @@ export const updatePost = async (id: number, post: Partial<Post>): Promise<Post>
7272
}
7373

7474
export const deletePost = async (id: number): Promise<void> => {
75-
await fetch(`/api/posts/${id}`, {
75+
await fetch(createApiUrl(`posts/${id}`), {
7676
method: "DELETE",
7777
})
7878
}
7979

8080
export const fetchTags = async () => {
81-
const response = await fetch("/api/posts/tags")
81+
const response = await fetch(createApiUrl("posts/tags"))
8282
return response.json()
8383
}

src/entities/user/api/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
import { createApiUrl } from "@shared/lib"
12
import { User, UsersApiResponse } from "@entities/user/model/types"
23

34
// Export hooks
45
export * from "./queries"
56

67
export const fetchUsers = async (params?: string): Promise<UsersApiResponse> => {
7-
const url = params ? `/api/users?${params}` : "/api/users"
8-
const response = await fetch(url)
8+
const path = params ? `users?${params}` : "users"
9+
const response = await fetch(createApiUrl(path))
910
return response.json()
1011
}
1112

1213
export const fetchUser = async (id: number): Promise<User> => {
13-
const response = await fetch(`/api/users/${id}`)
14+
const response = await fetch(createApiUrl(`users/${id}`))
1415
return response.json()
1516
}

src/shared/lib/api-config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* API configuration for different environments
3+
*/
4+
export const API_BASE_URL = import.meta.env.PROD ? "https://dummyjson.com" : "/api"
5+
6+
/**
7+
* Create API URL with proper base
8+
*/
9+
export const createApiUrl = (path: string): string => {
10+
// Remove leading slash if present to avoid double slashes
11+
const cleanPath = path.startsWith("/") ? path.slice(1) : path
12+
return `${API_BASE_URL}/${cleanPath}`
13+
}

src/shared/lib/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ export * from "./url-utils"
66

77
// React Query optimistic utils
88
export * from "./react-query-optimistic"
9+
10+
// API configuration
11+
export * from "./api-config"

0 commit comments

Comments
 (0)