-
Notifications
You must be signed in to change notification settings - Fork 0
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
Fix/proxy cors #215
Fix/proxy cors #215
Conversation
Codecov ReportPatch and project coverage have no change.
Additional details and impacted files@@ Coverage Diff @@
## develop #215 +/- ##
========================================
Coverage 95.38% 95.38%
========================================
Files 16 16
Lines 130 130
Branches 18 18
========================================
Hits 124 124
Misses 6 6 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀
Left a comment, but it's just a question and not really a request for changes!
@@ -11,3 +11,6 @@ export const GET: RequestHandler = dispatchToBackend; | |||
export const POST: RequestHandler = dispatchToBackend; | |||
export const PUT: RequestHandler = dispatchToBackend; | |||
export const DELETE: RequestHandler = dispatchToBackend; | |||
export const PATCH: RequestHandler = dispatchToBackend; | |||
export const OPTIONS: RequestHandler = dispatchToBackend; | |||
export const HEAD: RequestHandler = dispatchToBackend; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is adding CONNECT
and TRACE
as well worth it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not think so, they are not the type of requests we would do to the server via the frontend
Also, I know that it is out of the scope of this PR but won't this line (https://github.com/NIAEFEUP/website-niaefeup-frontend/pull/215/files#diff-4bcda89884a979801f8a542290893a21e5213fc48218ec305b5434ef11e70ddaR6) cause an error when the request body is, for instance, an image? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I just noticed that HEAD
and OPTIONS
requests don't have a body. Line 6 of +server.ts
should be changed accordingly. I also left another suggestion so let me know what you think.
if (window?.location?.origin) { | ||
headers.append('Origin', window.location.origin); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the Origin
header is automatically added by browsers when fetch
is called, so it shouldn't be necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is, it's just a way to make sure it is there. I'm not sure how could we have a cors problem otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the cors problem was because OPTIONS
requests (used by CORS) weren't being proxied to the backend. I'll approve either way.
I am not sure that it would cause an error (did a quick search and the docs do not appear to mention that), maybe it will simply be a utf-8 string representation of the bytes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀
From my testing, you're right, it doesn't error. However, it still means we won't be able to upload images (or other binary formats) properly to our backend. I'll open the issue. |
I can't test because of this error:
Did you encounter it? |
That issue has been fixed in SvelteKit v1.22.0 (https://github.com/sveltejs/kit/blob/master/packages/kit/CHANGELOG.md). I just noticed that we are using the dependency "@sveltejs/kit" with the tag "next". As per this page, that will resolve to version "1.0.0-next.589". We might want to change the tag in the package.json file to "latest" or something else as that version is very outdated (7 months old). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, the issue should be solved after bumping sveltekit version
Closes #158
Review checklist