Skip to content

Commit fc55c04

Browse files
committed
feature: configure http mode development
1 parent 3076426 commit fc55c04

File tree

5 files changed

+67
-10
lines changed

5 files changed

+67
-10
lines changed

frontend/config/dependencies.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ import InMemoryUserConfigRepository from '../src/Infrastructure/Memory/InMemoryU
1414
import SupabaseAuthRepository from '../src/Infrastructure/Supabase/SupabaseAuthRepository.ts'
1515
import SupabaseGameRepository from '../src/Infrastructure/Supabase/SupabaseGameRepository.ts'
1616

17-
import { getInheritDriver, getSessionDriver, isDevelopmentMode } from './env.ts'
17+
import { getInheritDriver, getSessionDriver, getDevelopmentMode } from './env.ts'
18+
import HttpGameRepository from '../src/Infrastructure/Http/HttpGameRepository.ts'
1819

1920
const binds: DriverResolver = {
2021
[DriverType.json]: {
2122
GameRepository: () => new InMemoryGameRepository(),
2223
},
2324
[DriverType.http]: {
2425
AuthRepository: () => HttpAuthRepository.build(),
25-
GameRepository: () => new InMemoryGameRepository(),
26+
GameRepository: () => HttpGameRepository.build(),
2627
},
2728
[DriverType.memory]: {
2829
AuthRepository: () => new InMemoryAuthRepository(),
@@ -56,9 +57,10 @@ export default function () {
5657
container.register('AuthService', { useClass: AuthService })
5758

5859
let authDriver: Driver = getInheritDriver()
59-
if (isDevelopmentMode()) {
60+
const type = getDevelopmentMode()
61+
if (type) {
6062
authDriver = {
61-
type: DriverType.memory,
63+
type: type,
6264
config: {}
6365
}
6466
}

frontend/config/env.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
import { getInitialSession, sessionStore } from '../view/stores/session.ts'
2-
import { Driver } from '../src/Domain/Contracts.ts'
2+
import { Driver, DriverType } from '../src/Domain/Contracts.ts'
33

44
export const getInheritDriver = (): Driver => getInitialSession().driver
55

66
export const getSessionDriver = (): Driver => sessionStore.state.driver
77

8-
export const isDevelopmentMode = (): boolean => import.meta.env.VITE_DEVELOPMENT_MODE === 'true'
8+
export const getDevelopmentMode = (): DriverType | undefined => {
9+
const type = import.meta.env.VITE_DEVELOPMENT_DRIVER_TYPE
10+
switch (type) {
11+
case 'http':
12+
return DriverType.http
13+
case 'memory':
14+
return DriverType.memory
15+
default:
16+
return undefined
17+
}
18+
}

frontend/docker-compose.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
services:
2+
quiz-node:
3+
container_name: quiz-node
4+
image: node:20-alpine
5+
working_dir: /var/www
6+
volumes:
7+
- .:/var/www
8+
command: >
9+
sh -c "npm install && npm run dev -- --host"
10+
ports:
11+
- "5173:5173"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import GameRepository from '../../Domain/Game/GameRepository.ts'
2+
import Game from '../../Domain/Game/Game.ts'
3+
import { HttpClientDriverContract } from '../Driver/Http/Contracts.ts'
4+
import HttpClientFactory from '../Driver/Http/HttpClientFactory.ts'
5+
import { Status } from '../../Domain/Contracts.ts'
6+
7+
export default class HttpGameRepository implements GameRepository {
8+
private http: HttpClientDriverContract
9+
10+
constructor (factory: HttpClientFactory) {
11+
this.http = factory.make()
12+
}
13+
14+
static build () {
15+
return new this(new HttpClientFactory())
16+
}
17+
18+
async findById (id: number | string): Promise<Game> {
19+
const response = await this.http.get(`/api/v1/games/${id}`)
20+
if (response.status !== Status.success) {
21+
throw new Error(response.message)
22+
}
23+
return response.data as unknown as Game
24+
}
25+
26+
async paginate (page: number, limit: number): Promise<Game[]> {
27+
const response = await this.http.get(`/api/v1/games?page=${page}&limit=${limit}`)
28+
if (response.status !== Status.success) {
29+
throw new Error(response.message)
30+
}
31+
return response.data as unknown as Game[]
32+
}
33+
}

frontend/view/pages/public/auth/SignInPage.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useNavigate } from 'react-router-dom'
22

3-
import { isDevelopmentMode } from '../../../../config/env.ts'
3+
import { getDevelopmentMode } from '../../../../config/env.ts'
44
import { Session } from '../../../../src/Domain/Auth/Auth.ts'
55
import { DriverType } from '../../../../src/Domain/Contracts.ts'
66

@@ -20,9 +20,10 @@ export function SignInPage () {
2020
const { loading } = useLoading()
2121

2222
const type = session.driver.type === DriverType.supabase ? 'otp' : 'password'
23-
const initial = {
24-
username: isDevelopmentMode() ? '[email protected]' : '',
25-
password: isDevelopmentMode() ? '***************' : ''
23+
const isDevelopment = !!getDevelopmentMode()
24+
const initial: SignInData = {
25+
username: isDevelopment ? '[email protected]' : '',
26+
password: isDevelopment ? '***************' : ''
2627
}
2728
const {
2829
value,

0 commit comments

Comments
 (0)