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

Static frontend + API/Function #311

Open
NamesMT opened this issue Apr 26, 2024 · 7 comments · May be fixed by #320
Open

Static frontend + API/Function #311

NamesMT opened this issue Apr 26, 2024 · 7 comments · May be fixed by #320
Assignees

Comments

@NamesMT
Copy link
Contributor

NamesMT commented Apr 26, 2024

Hi,
I'm trying to achieve a deployment of which it's similar to StaticSite where we only build and deploy the site's frontend on sst deploy, not sst dev, with the ability to link to an API/Function to host in the same Cdn and custom domain, like:

routes: {
  "/*": myStaticFrontend,
  "/api/*": myFunction.url
}

Is it possible / how clean is it to achieve in the current state of Ion?

@NamesMT NamesMT changed the title Static frontend + API Static frontend + API/Function Apr 26, 2024
@NamesMT
Copy link
Contributor Author

NamesMT commented Apr 26, 2024

Basically, a stack for a Client-side rendered SPA + backend on same distribution/domain

@NamesMT
Copy link
Contributor Author

NamesMT commented Apr 26, 2024

I hacked a working prototype copied from StaticSite: static-site-with-backend.ts
Tested with working dev + deploy.

Image:
image

@jayair
Copy link
Contributor

jayair commented Apr 26, 2024

Would putting a Router in front of both the static site and API work?

@NamesMT
Copy link
Contributor Author

NamesMT commented Apr 27, 2024

It might but basically anyone that looks at the result would yell (not in a good way).
Both StaticSite and Router creates a Cloudfront distribution (Cdn), so we'd put a Cloudfront in front of another Cloudfront.

@NamesMT
Copy link
Contributor Author

NamesMT commented Apr 27, 2024

I think the best way would be refactoring StaticSite or deprecating it and creates a new one which uses Router under the hood and exposes an arg to configure the routes, this allows for a DRY-er code and always align StaticSite routing behavior with Router if we update it.
Or if you want it to be simpler we could re-implement the routes arg to StaticSite.

@NamesMT NamesMT linked a pull request Apr 27, 2024 that will close this issue
@NamesMT
Copy link
Contributor Author

NamesMT commented Apr 30, 2024

Alternatively could be solved with an improved Router in #340.

Maybe out of topic but would be great if we could implement an Assets component or improve Bucket to support building the static frontend for a better experience when using Router.

@jayair
Copy link
Contributor

jayair commented May 3, 2024

Yeah we need to review this a bit. It might need a design change.

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

Successfully merging a pull request may close this issue.

3 participants