Skip to content

Commit

Permalink
revert
Browse files Browse the repository at this point in the history
  • Loading branch information
ruggi committed Feb 20, 2024
1 parent 6c6e05b commit 77edbb1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 71 deletions.
7 changes: 3 additions & 4 deletions utopia-remix/app/util/api.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { getUserFromSession } from '../models/session.server'
import * as cookie from 'cookie'
import { Params } from '@remix-run/react'
import { PrismaClientKnownRequestError } from 'prisma-client/runtime/library.js'
import { AxiosResponse } from 'axios'

interface ErrorResponse {
error: string
Expand Down Expand Up @@ -114,15 +113,15 @@ export function ensure(condition: unknown, message: string, status: number): ass
}
}

export async function proxiedResponse(response: AxiosResponse): Promise<unknown> {
export async function proxiedResponse(response: Response): Promise<unknown> {
if (response.status !== Status.OK) {
let text = await response.data
let text = await response.text()
if (text.length === 0) {
text = response.statusText
}
throw new ApiError(text, response.status)
}
return response.data
return response.json()
}

export const SESSION_COOKIE_NAME = 'JSESSIONID'
Expand Down
21 changes: 6 additions & 15 deletions utopia-remix/app/util/proxy.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import urljoin from 'url-join'
import { ServerEnvironment } from '../env.server'
import { proxiedResponse } from './api.server'
import dns from 'dns'
import axios, { AxiosHeaders } from 'axios'

if (ServerEnvironment.environment === 'local') {
// this is a workaround for default DNS resolution order with Node > 17 (where ipv6 comes first)
Expand All @@ -26,23 +25,15 @@ export async function proxy(req: Request, options?: { rawOutput?: boolean; path?
const url = buildProxyUrl(new URL(req.url), options?.path ?? null)

console.log(`proxying call to ${url}`)
const headers = new AxiosHeaders()
for (const [key, value] of req.headers) {
headers.set(key, value)
}

const data = await req.blob()

const resp = await axios.request({
url: url,
const response = await fetch(url, {
credentials: 'include',
method: req.method,
headers: headers,
data: data,
withCredentials: true,
body: req.body,
headers: req.headers,
})

if (options?.rawOutput) {
return resp
return response
}
return proxiedResponse(resp)
return proxiedResponse(response)
}
1 change: 0 additions & 1 deletion utopia-remix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"@remix-run/node": "2.5.1",
"@remix-run/react": "2.5.1",
"@remix-run/serve": "2.5.1",
"axios": "1.6.7",
"cookie": "0.6.0",
"dotenv": "16.4.1",
"isbot": "4",
Expand Down
51 changes: 0 additions & 51 deletions utopia-remix/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 77edbb1

Please sign in to comment.