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

Redirect all frontend routes to start-instance until configured #41

Closed
petebacondarwin opened this issue Jan 9, 2023 · 5 comments
Closed

Comments

@petebacondarwin
Copy link
Collaborator

No description provided.

@xtuc
Copy link
Member

xtuc commented Jan 9, 2023

I intentially didn't do it to avoid adding a D1 query on all requests.

@petebacondarwin
Copy link
Collaborator Author

But don't we hit D1 on every frontend UI request anyway? Especially now that we are reading the thumbnail etc from the DB?
In the data loader for access the instance-config, we could trigger a redirect if no data is returned.

@xtuc
Copy link
Member

xtuc commented Jan 9, 2023

We would need to query D1 to detect that the instance hasn't been configured.

@petebacondarwin
Copy link
Collaborator Author

This code runs on every frontend request:

export const instanceLoader = loader$<{ DATABASE: D1Database; domain: string }, Promise<InstanceConfig>>(
async ({ platform }) => {
const response = await instance.handleRequest('', platform.DATABASE)
const results = await response.text()
const json = JSON.parse(results) as InstanceConfig
return json
}
)

In this function, we can check whether the config exists (rather than just naively casting it) and throw a response.redirect() to push the user to the start-instance page instead.

@petebacondarwin
Copy link
Collaborator Author

petebacondarwin commented Jan 9, 2023

And if this is problematic (from a performance point of view) we need to implement some caching of the instance data in the system somewhere (outside of D1) perhaps in a KV?

@xtuc xtuc closed this as completed Jan 11, 2023
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

2 participants