Skip to content

Commit

Permalink
feature: configure http mode development
Browse files Browse the repository at this point in the history
  • Loading branch information
wilcorrea committed May 2, 2024
1 parent 3076426 commit fc55c04
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 10 deletions.
10 changes: 6 additions & 4 deletions frontend/config/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ import InMemoryUserConfigRepository from '../src/Infrastructure/Memory/InMemoryU
import SupabaseAuthRepository from '../src/Infrastructure/Supabase/SupabaseAuthRepository.ts'
import SupabaseGameRepository from '../src/Infrastructure/Supabase/SupabaseGameRepository.ts'

import { getInheritDriver, getSessionDriver, isDevelopmentMode } from './env.ts'
import { getInheritDriver, getSessionDriver, getDevelopmentMode } from './env.ts'
import HttpGameRepository from '../src/Infrastructure/Http/HttpGameRepository.ts'

const binds: DriverResolver = {
[DriverType.json]: {
GameRepository: () => new InMemoryGameRepository(),
},
[DriverType.http]: {
AuthRepository: () => HttpAuthRepository.build(),
GameRepository: () => new InMemoryGameRepository(),
GameRepository: () => HttpGameRepository.build(),
},
[DriverType.memory]: {
AuthRepository: () => new InMemoryAuthRepository(),
Expand Down Expand Up @@ -56,9 +57,10 @@ export default function () {
container.register('AuthService', { useClass: AuthService })

let authDriver: Driver = getInheritDriver()
if (isDevelopmentMode()) {
const type = getDevelopmentMode()
if (type) {
authDriver = {
type: DriverType.memory,
type: type,
config: {}
}
}
Expand Down
14 changes: 12 additions & 2 deletions frontend/config/env.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import { getInitialSession, sessionStore } from '../view/stores/session.ts'
import { Driver } from '../src/Domain/Contracts.ts'
import { Driver, DriverType } from '../src/Domain/Contracts.ts'

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

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

export const isDevelopmentMode = (): boolean => import.meta.env.VITE_DEVELOPMENT_MODE === 'true'
export const getDevelopmentMode = (): DriverType | undefined => {
const type = import.meta.env.VITE_DEVELOPMENT_DRIVER_TYPE
switch (type) {
case 'http':
return DriverType.http
case 'memory':
return DriverType.memory
default:
return undefined
}
}
11 changes: 11 additions & 0 deletions frontend/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
services:
quiz-node:
container_name: quiz-node
image: node:20-alpine
working_dir: /var/www
volumes:
- .:/var/www
command: >
sh -c "npm install && npm run dev -- --host"
ports:
- "5173:5173"
33 changes: 33 additions & 0 deletions frontend/src/Infrastructure/Http/HttpGameRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import GameRepository from '../../Domain/Game/GameRepository.ts'
import Game from '../../Domain/Game/Game.ts'
import { HttpClientDriverContract } from '../Driver/Http/Contracts.ts'
import HttpClientFactory from '../Driver/Http/HttpClientFactory.ts'
import { Status } from '../../Domain/Contracts.ts'

export default class HttpGameRepository implements GameRepository {
private http: HttpClientDriverContract

constructor (factory: HttpClientFactory) {
this.http = factory.make()
}

static build () {
return new this(new HttpClientFactory())
}

async findById (id: number | string): Promise<Game> {
const response = await this.http.get(`/api/v1/games/${id}`)
if (response.status !== Status.success) {
throw new Error(response.message)
}
return response.data as unknown as Game
}

async paginate (page: number, limit: number): Promise<Game[]> {
const response = await this.http.get(`/api/v1/games?page=${page}&limit=${limit}`)
if (response.status !== Status.success) {
throw new Error(response.message)
}
return response.data as unknown as Game[]
}
}
9 changes: 5 additions & 4 deletions frontend/view/pages/public/auth/SignInPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useNavigate } from 'react-router-dom'

import { isDevelopmentMode } from '../../../../config/env.ts'
import { getDevelopmentMode } from '../../../../config/env.ts'
import { Session } from '../../../../src/Domain/Auth/Auth.ts'
import { DriverType } from '../../../../src/Domain/Contracts.ts'

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

const type = session.driver.type === DriverType.supabase ? 'otp' : 'password'
const initial = {
username: isDevelopmentMode() ? '[email protected]' : '',
password: isDevelopmentMode() ? '***************' : ''
const isDevelopment = !!getDevelopmentMode()
const initial: SignInData = {
username: isDevelopment ? '[email protected]' : '',
password: isDevelopment ? '***************' : ''
}
const {
value,
Expand Down

0 comments on commit fc55c04

Please sign in to comment.