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

How can I get S3 to use correct MIME types for static content? #73

Closed
mikemaccana opened this issue Jan 21, 2019 · 15 comments
Closed

How can I get S3 to use correct MIME types for static content? #73

mikemaccana opened this issue Jan 21, 2019 · 15 comments

Comments

@mikemaccana
Copy link
Contributor

mikemaccana commented Jan 21, 2019

This is probably a documentation issue. As in, I don't understand how to do something and the current static docs don't tell me.

Quick question

Minor note: the docs don't cover this, but since S3 doesn't have 'real' folders (and looking at the other arc-examples), I guess /static should be flat and not have folders (folders do work on sandbox though, which is why I'm confused). Is that correct?

Issue

Source code: https://github.com/arc-repos/arc-example-notes, using arc 4.5.6

On sandbox:

image

On staging:

image

CORB error:

image

Edit: Note this is CORB not CORS.

@mikemaccana
Copy link
Contributor Author

Oooh wait this is CORB not CORS....

@mikemaccana
Copy link
Contributor Author

From reading https://www.chromium.org/Home/chromium-security/corb-for-developers it looks like the MIME type being sent incorrectly from S3 is causing the issue.

How can I get S3 to use correct MIME types for static content?

@mikemaccana mikemaccana changed the title CORS blocking static assets How can I get S3 to use correct MIME types for static content? Jan 21, 2019
@brianleroux
Copy link
Member

Could be a bug w upload code in deploy. You can change mimes in the S3 console. Just walking but will be atta machine shortly

@mikemaccana
Copy link
Contributor Author

Thanks for the quick reply, that would be cool. I'll get into the console now. Am I right that /static has to be flat?

@brianleroux
Copy link
Member

Nope! Just can't have empty folders is all

@mikemaccana
Copy link
Contributor Author

Yeah it looks like you're right: the deploy code is trying to replicate the entire directory structure on S3:

    ✓ https://s3.us-east-1.amazonaws.com/arc-example-notes-staging/:/Users/mikem/OneDrive/Documents/arc-
example-notes/public/style.css

image

@mikemaccana
Copy link
Contributor Author

Opening _copy_to_s3.js and changing:

var key = file.replace(path.join(process.cwd(), 'public'), '').substr(1)

To:

var key = file.replace(/.*\/public/, '').substr(1)

And running npx deploy returns:

✓ https://s3.us-east-1.amazonaws.com/arc-example-notes-staging/forms.css
✓ https://s3.us-east-1.amazonaws.com/arc-example-notes-staging/cards.css
✓ https://s3.us-east-1.amazonaws.com/arc-example-notes-staging/architect-favicon-32.png
✓ https://s3.us-east-1.amazonaws.com/arc-example-notes-staging/architect-favicon-16.png
✓ https://s3.us-east-1.amazonaws.com/arc-example-notes-staging/fonts.css
✓ https://s3.us-east-1.amazonaws.com/arc-example-notes-staging/style.css
✓ https://s3.us-east-1.amazonaws.com/arc-example-notes-staging/logo.svg
✓ https://s3.us-east-1.amazonaws.com/arc-example-notes-staging/hero.css
✓ https://s3.us-east-1.amazonaws.com/arc-example-notes-staging/nav.css
✓ https://s3.us-east-1.amazonaws.com/arc-example-notes-staging/logo-light.svg
✓ https://s3.us-east-1.amazonaws.com/arc-example-notes-staging/architect-favicon-64.png
✓ https://s3.us-east-1.amazonaws.com/arc-example-notes-staging/readme.md
✓ https://s3.us-east-1.amazonaws.com/arc-example-notes-staging/metrics.css
✓ https://s3.us-east-1.amazonaws.com/arc-example-notes-staging/colors.css

Which appear correct. However those files (unlike the ones above) do not appear in the S3 console. Is there some better way to redeploy static than npx deploy?

@mikemaccana
Copy link
Contributor Author

PS the bug is a slash normalisation issue:

path.join(process.cwd(), 'public')

Is C:\Users\mikem\OneDrive\Documents\arc-example-notes\public

Let's call that publicDir

file.replace(publicDir, '')

Is C:/Users/mikem/OneDrive/Documents/arc-example-notes/public/architect-favicon-16.png

Note the different slashes.

So that solves the first part (I'll send a PR). But why is the deploy not working?

@mikemaccana
Copy link
Contributor Author

Looks like the files just took a moment to appear n S3:

image

@mikemaccana
Copy link
Contributor Author

I think I'm good for this, hitting dance/gym now but PR incoming later tonight

@mikemaccana
Copy link
Contributor Author

Also for my own ref (and maybe yours): nodejs/node#8237

@brianleroux
Copy link
Member

huh, TIL

@mikemaccana
Copy link
Contributor Author

OK npx deploy now pushing files to the correct location on S3 per the PR above.

But content types still aren't being set properly (everything is application/xml and gets blocked accordingly by the browser).

Setting content type manually doesn't work either:

image

image

It's getting late here now so can check again in morning, but if you have any ideas re: content types (maybe check out and deploy https://github.com/arc-repos/arc-example-notes) it would be useful.

@mikemaccana
Copy link
Contributor Author

mikemaccana commented Jan 22, 2019

This is resolved (once the PR is merged) now - I wiped and remade the bucket, used the code in the PR to npx deploy static and I'm getting the correct MIME types now.

Please close once architect/architect#269 is merged.

@mikemaccana
Copy link
Contributor Author

Actually going to close this anyway since it's for the wrong repo.

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

No branches or pull requests

2 participants