Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared shadow endpoint #3735

Closed
livehtml opened this issue Feb 5, 2022 · 2 comments
Closed

Shared shadow endpoint #3735

livehtml opened this issue Feb 5, 2022 · 2 comments

Comments

@livehtml
Copy link

livehtml commented Feb 5, 2022

Describe the problem

Is it possible to have one shared shadow endpoint for several .svelte pages?

For example, we have public pages: index.svelte, about.svelte, privacy-policy.svelte
And for all these pages need to retrieve identical information from server about the user (logged or not, unreaded messages to show counter, etc)

So, how can we use say index.js endpoint? This filename will work with index.svelte, but not with the others pages. Renaming to [index].js or [...index].js breaks at all.

Current workaround I found is using the 'old' way with load and fetch in all other than index.svelte pages:

export const load = async ({ fetch }) => {
    const res = await fetch('/', { headers: { accept: 'application/json'}});
    
    if (res.ok) {
        return {
            props: await res.json()
        }
    }

    const { message } = await res.json();

    return {
        status: res.status,
        error: new Error(message)
    };
}; 

But I'm not sure how good this solution is.

Describe the proposed solution

Ability to pair one endpoint with many pages. May be with regex like filename:
[index|about|privacy-policy].js

Alternatives considered

No response

Importance

would make my life easier

Additional Information

No response

@brittneypostma
Copy link
Contributor

I do like this idea, similar to a layout but maybe an __endpoint.js file to load multiple routes with data. I would also love the ability to actually import an endpoint into routes instead of the pure magic load. This would allow the endpoints to be placed away from the routes also.

@Rich-Harris
Copy link
Member

The solution here isn't to have a shared page endpoint, it's to have layout endpoints — closing this in favour of #4274

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants