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

Feature - Better static assets support #89

Closed
danielcondemarin opened this issue Jun 14, 2019 · 6 comments
Closed

Feature - Better static assets support #89

danielcondemarin opened this issue Jun 14, 2019 · 6 comments
Labels
enhancement New feature or request

Comments

@danielcondemarin
Copy link
Contributor

Original discussion: #88

Motivation

Currently it is only possible to host static assets at the top level of the api gw domain, e.g. /robots.txt, /sw.js etc. Nested static routes doesn't work, e.g. /static/bar.png, /static/foo.txt etc.
Also, the existing approach doesn't follow nextjs convention for static/ and public/ folders. Would be better to follow next's convention to ensure feature parity with the development server.

Proposal

Add a catch all /static/{proxy+} route to api gateway that proxies to S3 static assets requests.
Note that static assets will only be possible to host them under the static folder with this approach, which differs from the current api.
Host any files under ./public in the top level path, resources such as robots.txt, favicon.ico etc.
Nextjs docs: (https://github.com/zeit/next.js/#static-file-serving-eg-images)

Caveats

A better approach would be to have a CloudFront distribution in front of API Gateway. API Gateway data transfer out costs is $0.09 per GB whilst CloudFront is $0.085 for the first TB.
A separate feature request will be made to add CloudFront support for production deployments.

@danielcondemarin
Copy link
Contributor Author

@mattdell Are you interested to contribute towards this?

@danielcondemarin danielcondemarin added the enhancement New feature or request label Jun 14, 2019
@mattdell
Copy link
Contributor

@danielcondemarin I’m willing to take a crack at it. Let me assess my workload on Monday and hopefully I can dedicate some time to this. 🙂

@mattdell
Copy link
Contributor

Looks like I'm good to spend a few days on this. Feel free to mark it as assigned to me.

@mattdell
Copy link
Contributor

mattdell commented Jun 19, 2019

I've got this working, just need to write some unit tests to finish it off and then I'll raise a PR.

Just to confirm, do we want to keep the existing routes configuration?

    routes:
      - src: ./assets/robots.txt
        path: robots.txt

This scenario is no longer needed as you'd just use the public folder. Also, I've made the static and public folders configurable in serverless.yml so public could be assets if desired.

I'm not sure if routes is in the existing stable version or whether this would be a breaking change. I don't mind either way, but at the moment it seems superfluous.

@danielcondemarin
Copy link
Contributor Author

Just to confirm, do we want to keep the existing routes configuration?

No need to keep that for static routes. Page routes we have to keep for the time being until this lands: vercel/next.js#7607.

I'm not sure if routes is in the existing stable version or whether this would be a breaking change. I don't mind either way, but at the moment it seems superfluous.

Don't worry about making it a breaking change, v2 is still in alpha.

@danielcondemarin
Copy link
Contributor Author

Closed by #92

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

No branches or pull requests

2 participants