Skip to content

Commit

Permalink
Fix fetch urls
Browse files Browse the repository at this point in the history
  • Loading branch information
whaaaley committed Nov 24, 2024
1 parent 37bd870 commit e0e1a4d
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 14 deletions.
1 change: 1 addition & 0 deletions client/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_API_PREFIX=http://localhost:4202
1 change: 1 addition & 0 deletions client/.env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_API_PREFIX=
17 changes: 10 additions & 7 deletions client/src/promisePipelines/fetchPipeline.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { httpMiddleware, marshalMiddleware, zodMiddleware } from './middleware/index'
import * as middleware from './middleware/index'
import { useWithGet, useWithPost } from '~/composables/useWithFetch'

export const withGet = useWithGet()
export const withPost = useWithPost()

withGet.useBefore(marshalMiddleware)
withPost.useBefore(marshalMiddleware)
withGet.useBefore(middleware.devMiddleware)
withPost.useBefore(middleware.devMiddleware)

withGet.useAfter(httpMiddleware)
withPost.useAfter(httpMiddleware)
withGet.useBefore(middleware.marshalMiddleware)
withPost.useBefore(middleware.marshalMiddleware)

withGet.useAfter(zodMiddleware)
withPost.useAfter(zodMiddleware)
withGet.useAfter(middleware.httpMiddleware)
withPost.useAfter(middleware.httpMiddleware)

withGet.useAfter(middleware.zodMiddleware)
withPost.useAfter(middleware.zodMiddleware)
8 changes: 8 additions & 0 deletions client/src/promisePipelines/middleware/devMiddleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Middleware } from '~/composables/useWith'
import { RequestContext } from '~/composables/useWithFetch'

export const devMiddleware: Middleware<RequestContext> = async (context) => {
context.url = import.meta.env.VITE_API_PREFIX + context.url
console.log('devMiddleware', context.url)
return context
}
1 change: 1 addition & 0 deletions client/src/promisePipelines/middleware/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { authMiddleware } from './authMiddleware'
export { devMiddleware } from './devMiddleware'
export { httpMiddleware } from './httpMiddleware.ts'
export { marshalMiddleware } from './marshalMiddleware.ts'
export { zodMiddleware } from './zodMiddleware'
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const marshalMiddleware: Middleware<RequestContext> = async (context) =>
}

if (context.body) {
console.log('context.body', context.body, typeof context.body)
context.body = JSON.stringify(context.body)
context.headers = {
...context.headers,
Expand Down
8 changes: 8 additions & 0 deletions client/src/promisePipelines/sseMiddleware/devMiddleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Middleware } from '~/composables/useWith'
import { RequestContext } from '~/composables/useWithSSE'

export const devMiddleware: Middleware<RequestContext> = async (context) => {
context.url = import.meta.env.VITE_API_PREFIX + context.url
console.log('devMiddleware', context.url)
return context
}
1 change: 1 addition & 0 deletions client/src/promisePipelines/sseMiddleware/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { devMiddleware } from './devMiddleware'
export { loggingMiddleware } from './loggingMiddleware'
export { unmarshalMiddleware } from './unmarshalMiddleware'
6 changes: 4 additions & 2 deletions client/src/promisePipelines/ssePiepeline.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { unmarshalMiddleware } from './sseMiddleware/index'
import * as middleware from './sseMiddleware/index'
import { useWithSSE } from '~/composables/useWithSSE'

export const withSSE = useWithSSE()

withSSE.useAfter(unmarshalMiddleware)
withSSE.useBefore(middleware.devMiddleware)

withSSE.useAfter(middleware.unmarshalMiddleware)
// withSSE.useAfter(loggingMiddleware)
2 changes: 1 addition & 1 deletion client/src/queries/emojiQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type WeatherEmojiResponse = z.infer<typeof WeatherEmojiResponseSchema>
export const emojiQueries = {
getWeatherEmoji: async (params: GetWeatherEmojiParams) => (
withGet.execute({
url: 'http://localhost:4202/api/weather-emoji',
url: '/api/weather-emoji',
queryString: params,
responseSchema: WeatherEmojiResponseSchema,
headers: {
Expand Down
4 changes: 2 additions & 2 deletions client/src/queries/logStreamQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type LogResponse = z.infer<typeof LogResponseSchema>
export const logStreamQueries = {
connectLogs: async (params: ConnectLogsParams) => {
const { data } = await withSSE.execute({
url: 'http://localhost:4202/stream/logs',
url: '/stream/logs',
responseSchema: LogResponseSchema,
onMessage: params.onMessage,
})
Expand All @@ -44,7 +44,7 @@ export const logStreamQueries = {
},
sendLog: async (params: SendLogParams) => {
const { data } = await withPost.execute({
url: 'http://localhost:4202/api/log',
url: '/api/log',
body: params,
responseSchema: LogResponseSchema,
})
Expand Down
2 changes: 1 addition & 1 deletion client/src/queries/weatherQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type WeatherResponse = z.infer<typeof WeatherResponseSchema>
export const weatherQueries = {
getWeather: async (params: GetWeatherParams) => {
const { data } = await withGet.execute({
url: 'http://localhost:4202/api/weather',
url: '/api/weather',
queryString: params,
responseSchema: WeatherResponseSchema,
headers: {
Expand Down

0 comments on commit e0e1a4d

Please sign in to comment.