Skip to content

Commit b2db763

Browse files
aster-voidclaude
andauthored
バックエンドと接続 (#70)
- Course をバックエンドから読み込み - ユーザー情報読み込み - 開発時に、 Vite からバックエンドサーバーに /api 以下のルートをプロキシ - これをしないと Cookie の同オリジン制限で認証が動かない --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6599095 commit b2db763

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1033
-457
lines changed

.env.sample

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# Config
2-
PUBLIC_SERVER_URL=http://localhost:4000
32
PUBLIC_MOCK_DATA=true
4-
SERVER_PORT=4000 # optional, server port (alias: PORT, PUBLIC_SERVER_URL.port) (defaults to 4000 if none are specified)
53

6-
# Secrets
7-
PUBLIC_X_ANON_KEY=...
8-
X_API_KEY=...
4+
# 開発中 -> Vite: BASE_URL.port, Elysia: EXTERNAL_SERVER_PORT
5+
# プロダクション -> Vite: - , Elysia: PORT ?? BASE_URL.port
6+
BASE_URL=http://localhost:3000
7+
EXTERNAL_SERVER_PORT=4000
98

9+
NODE_ENV=development
10+
11+
# Database
1012
DATABASE_URL=file:../../local.db
1113

14+
# Better Auth
1215
BETTER_AUTH_SECRET=...
13-
BETTER_AUTH_URL=http://localhost:4000
1416

1517
GOOGLE_CLIENT_ID=...
1618
GOOGLE_CLIENT_SECRET=
17-
18-
PUBLIC_WEB_URL=http://localhost:3000

.github/workflows/static-checks.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ on:
66
- main
77
pull_request:
88

9+
env:
10+
BASE_URL: http://localhost:3000
11+
EXTERNAL_SERVER_PORT: 4000
12+
913
jobs:
1014
build:
1115
name: Build
@@ -15,6 +19,7 @@ jobs:
1519
- uses: oven-sh/setup-bun@v2
1620
- run: bun install --frozen-lockfile
1721
- run: bun run build
22+
1823
biome:
1924
name: Biome Checks
2025
runs-on: ubuntu-latest

.github/workflows/test.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
bun:
11+
name: Bun Unit Tests
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 10
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: oven-sh/setup-bun@v2
17+
- run: bun install --frozen-lockfile
18+
- run: bun test

TODO.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# TODOs
22

3-
- setup elysia server and RPC
43
- implement build script

bun.lock

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

docs/developer_readme.md

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ bun db push
1616

1717
```bash
1818
# 開発モードを実行するには、以下のコマンドを実行してください。
19-
# localhost:5173 に Vite サーバーが立ち上がるので、そこで確認してください。
19+
# $BASE_URL に Vite サーバーが立ち上がるので、そこで確認してください。
2020
bun dev
2121

2222
# Storybookの使用
23-
# localhost:6006にStorybookが立ち上がるので、そこでUIを確認してください。
23+
# localhost:6006 にStorybookが立ち上がるので、そこでUIを確認してください。
2424
bun run storybook
2525
```
2626

@@ -36,28 +36,26 @@ bun check
3636
bun fix
3737
```
3838

39-
## モックモード
39+
## サーバー構成
4040

41-
モックモードを実行するには、以下のコマンドを実行してください。
41+
### 1. 開発中
4242

43-
```bash
44-
bun dev:mock
45-
```
43+
- Vite 開発サーバー (localhost:3000) -> すべてのリクエストはこのサーバーがプロキシ (ログインのリダイレクトを除く)
44+
- Elysia サーバー (localhost:4000) -> /api 以下のリクエストをプロキシされて受け取る
4645

47-
このコマンドを実行すると、モックデータを使用してアプリケーションが実行されます。
46+
### 2. プロダクション
4847

49-
## 関数やクラスの説明
48+
- Elysia サーバー (localhost:${PORT}) -> /api 以外は public/index.html を返す
5049

51-
### 1. Userのデータを扱う場合 (src/app/utils/user.ts)
50+
## モックモード
5251

53-
Userのデータは`User`クラスを使用して扱います。Userのデータは以下の場合があります
52+
モックモードを実行するには、以下のコマンドを実行してください
5453

55-
- `bun dev:mock`を実行した場合
56-
- Userはモックのデータが使用されます。
57-
- `bun dev`を実行した場合
58-
- UserはlocalStorageに保存されたデータが使用されます。
54+
```bash
55+
PUBLIC_MOCK_DATA=true bun dev
56+
```
5957

60-
ただ、まだユーザを登録する機能がないので、mockでユーザを作成する必要があります
58+
このコマンドを実行すると、モックデータを使用してアプリケーションが実行されます
6159

6260
## 推奨 VS Code 設定
6361

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,9 @@
1717
"devDependencies": {
1818
"@biomejs/biome": "^2.1.1",
1919
"concurrently": "^9.2.0"
20+
},
21+
"dependencies": {
22+
"@elysiajs/eden": "^1.3.2",
23+
"elysia": "^1.3.6"
2024
}
2125
}

packages/models/atoms.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { t } from "elysia";
2+
3+
// Stream って何? 教えて有識者
4+
// Course.importance に使われているよう?
5+
export type Stream = typeof Stream.static;
6+
export const Stream = t.UnionEnum(["s1", "s2", "s3", "l1", "l2", "l3"]);
7+
8+
/**
9+
* 授業コード
10+
* 例: 30003
11+
*/
12+
export type CourseCode = typeof CourseCode.static;
13+
export const CourseCode = t.RegExp("^\\d{5}$");
14+
15+
/**
16+
* 共通科目コード
17+
* 例:
18+
* - XAB-CD1001L2
19+
* - CAS-FC1871L1
20+
* - CAS-GC1L37S4
21+
* - CASPG1F40L3 // 絶対入力ミスだが、データにあるので対応しなければならない
22+
* 仕様: https://www.u-tokyo.ac.jp/ja/students/classes/course-numbering.html
23+
* 本当は CommonSubjectCode になるはずだが、公式が勝手に CommonCourseCode と読んでいる
24+
*/
25+
export type CommonCourseCode = typeof CommonCourseCode.static;
26+
export const CommonCourseCode = t.RegExp(
27+
`
28+
^[CFG] ${/* [1] 課程コード */ ""}
29+
(?:LA|ME|EN|LE|SC|AG|EC|AS|ED|PH|GL) ${/* [2] 開講学部・研究科(教育部)コード */ ""}
30+
-?
31+
[A-Z]{2} ${/* [3] 開講学科・専攻等コード */ ""}
32+
[1-7] ${/* [4] レベルコード */ ""}
33+
[0-9a-zA-Z]{3} ${/* [5] 整理番号 */ ""}
34+
[LSEPTZ] ${/* [6] 授業形態コード */ ""}
35+
[123459] ${/* [7] 使用言語コード */ ""}
36+
$`.replaceAll(/\s/g, ""),
37+
);
38+
39+
/**
40+
* 曜日。
41+
*/
42+
export type Day = typeof Day.static;
43+
export const Day = t.UnionEnum(["mon", "tue", "wed", "thu", "fri", "sat"]);
44+
45+
export type Period = typeof Period.static;
46+
export const Period = t.UnionEnum([1, 2, 3, 4, 5, 6]);
47+
48+
/**
49+
* 曜限。
50+
*/
51+
export type DayPeriod = typeof DayPeriod.static;
52+
export const DayPeriod = t.Object({
53+
day: Day,
54+
period: Period,
55+
});
56+
57+
/**
58+
* セメスターまたはターム。
59+
*/
60+
export type Semester = typeof Semester.static;
61+
export const Semester = t.UnionEnum(["S", "S1", "S2", "A", "A1", "A2"]);
62+
63+
// 使われていない。
64+
/**
65+
* 評価方法。
66+
*/
67+
export type Evaluation = typeof Evaluation.static;
68+
export const Evaluation = t.UnionEnum(["試験", "レポート", "出席", "平常"]);
69+
70+
/**
71+
* 単位の種類。
72+
*/
73+
export type ClassType = typeof ClassType.static;
74+
export const ClassType = t.UnionEnum(["基礎", "要求", "主題", "総合", "展開"]);
75+
76+
export type ClassSeries = typeof ClassSeries.static;
77+
export const ClassSeries = t.UnionEnum([
78+
"基礎",
79+
"要求",
80+
"主題",
81+
"展開",
82+
"総合L",
83+
"総合A",
84+
"総合B",
85+
"総合C",
86+
"総合D",
87+
"総合E",
88+
"総合F",
89+
]);

packages/models/mappings.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { Day } from "./atoms.ts";
2+
3+
export const dayMapping: { [key in Day]: string } = {
4+
mon: "月",
5+
tue: "火",
6+
wed: "水",
7+
thu: "木",
8+
fri: "金",
9+
sat: "土",
10+
};

0 commit comments

Comments
 (0)