Replies: 1 comment 2 replies
-
I'm unconvinced this is something Remix should support, I understand the benefit but this goes against the standard of how // app/services/get-items.ts
export async function getItems(args: GetItemsArgs): Promise<GetItemsResult> { ... }
// app/routes/api.items.ts
export async function loader({ request }: DataFunctionArgs) {
await authorizeFromHeaders(request.headers);
let argsFromRequest = extractArgsFromRequest()
let items = await getItems(argsFromRequest)
return json(items)
}
// app/routes/items.tsx
export async function loader({ request }: DataFunctionArgs) {
await authorizeFromCookies(request);
let argsFromRequest = extractArgsFromRequest()
let items = await getItems(argsFromRequest)
let anotherThing = await getAnotherThing(argsFromRequest)
return json({
items: reduceItemsDataToMinimum(items), // remove parts of items that UI doesn't need
anotherThing
})
}
export default function Component() {
let { items, anotherThing } = useLoaderData<typeof loader>()
// render ui using items and anotherThing
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
It would be great if Remix supported relative URLs when doing a
fetch()
from the server-side, like SvelteKit.In SvelteKit, you can make a
fetch()
request on the server using a relative URL. It allows sending a request API routes on the same project, but without the overhead of an actual HTTP call.In Remix,
Why?
The project I’m building exposes both API routes and a UI routes. The API part accesses many 3rd party services (database, cloud providers, APIs, auth provider).
Ideally, the loaders in the UI routes will invoke 3rd party services through the API routes.
Setting up local versions of these services can take a lot of work, especially if my task is to tweak some frontend. So I wanted to make it possible for developers to work on just the frontend part while connecting to a production backend.
Developers can choose to either run the front end against the same instance, or connect to the production instance (or any other instance).
In SvelteKit, this is easy because a
fetch()
call accepts relative URL. However in Remix it’s not clear what the URL should be, especially when it’s deployed to a serverless provider.I tried constructing an absolute URL from
request.url
, however on Netlify this results in the lambda function calling itself, which means it costs twice and there is double the overhead.Beta Was this translation helpful? Give feedback.
All reactions