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

[Temporary] Disable Netlify CORS Proxy #100

Closed
azu opened this issue Jul 18, 2023 · 5 comments · Fixed by #101 or #103
Closed

[Temporary] Disable Netlify CORS Proxy #100

azu opened this issue Jul 18, 2023 · 5 comments · Fixed by #101 or #103

Comments

@azu
Copy link
Owner

azu commented Jul 18, 2023

At 2023-07-19, We have disabled Netlify CORS Proxy.
It means that user can not fetch ironoreader API by default.

📝 Inoreader API does not support CORS. Instead of It, we have used CORS Proxy.

Workaround

You can use UserScript to connect Inoreader API directly.

What's happened

We have used Netlify's _redirect for CORS Proxy

/api/*  https://www.inoreader.com/reader/api/:splat  200
/token  https://www.inoreader.com/oauth2/token 200

However, This Proxy cached unknown response.

  • https://irodr.netlify.app/api/0/subscription/list

The response's Age is old, and return old results.
Additionaly, this endpoint ignore Authorization` request header and return the cache.

image

I've tests other API liks /api/0/user-info but it works.

After I deleted Netlify _redirect, but https://irodr.netlify.app/api/0/subscription/list still return unknown response. I tested Cross browser, Cross Device. (curl can not fetch the cache, it related to some header?)
I think something strange is happening to Netlify.

📝 I request https://irodr.netlify.app/api/0/subscription/list?1 and prune the cache.

Research

If the API supports standard HTTP caching mechanisms like ETags or Last-Modified headers, the responses will even get cached by our CDN nodes.
https://docs.netlify.com/routing/redirects/rewrites-proxies/#proxy-to-another-service

Inoreader API does not return the ETags and Last-Modified.

image

TODO

  • Move _redirect to netlify.toml (Same?)
  • Rewrite CORS Proxy with Edge Function?
  • Switch to UserScript only service?
  • Move to another service like Cloudflare Pages or Vercel?
    • These have Edge Function
    • The differences between the local and actual environment are reduced.
    • _redirect does not support local emurating
@azu azu changed the title Disable [Temporarly] Disable Netlify CORS Proxy Jul 18, 2023
@azu azu changed the title [Temporarly] Disable Netlify CORS Proxy [Temporary] Disable Netlify CORS Proxy Jul 18, 2023
@azu
Copy link
Owner Author

azu commented Jul 19, 2023

@azu
Copy link
Owner Author

azu commented Jul 19, 2023

Workaround: Always use cache busting parameter like ?cache={id}

Probably, Netlify cache the url with parameter. (So, I can purge cache via ?1)

We can avoid the cache by cache buster paramter.

/api/...?cache_buster_uuid=xxxxx

@azu azu linked a pull request Jul 19, 2023 that will close this issue
@azu azu closed this as completed in #101 Jul 19, 2023
@azu azu reopened this Jul 20, 2023
@azu
Copy link
Owner Author

azu commented Jul 20, 2023

https://irodr.netlify.app/api/0/subscription/list still return unknown cache.
We will drop to use Netlify's _redirect.

We have locked https://irodr.netlify.app/ untill fix this issue.

Workaround:

git clone https://github.com/azu/irodr
yarn install
yarn start

azu added a commit that referenced this issue Jul 20, 2023
azu added a commit that referenced this issue Jul 20, 2023
azu added a commit that referenced this issue Jul 20, 2023
@azu
Copy link
Owner Author

azu commented Jul 20, 2023

Workaround

You can use UserScript to connect Inoreader API directly.

* Clear IndexedDB, LocalStorage

* Install: https://github.com/azu/irodr/blob/master/resources/userScript/irodr-cors.js

Current Status. irodr require workaround scripts.

@azu
Copy link
Owner Author

azu commented Jul 22, 2023

Summary:


We have used Netlify Edge Function instead of _redirects proxy and fixed this issue.

I do not understand that _redirects cause this issue.
However, The behaviour of _redirect is so strange that we decided to avoid using it.

I wrote CORS Proxy as code using Edge Functions.

Proxy would have been avoided if possible, but other methods are not very usable.
Proxy has the risk that the operator(me) can peek into the user's Inoreader API communication.
To avoid this, we do not include console logs in the Proxy.

Of couse, You can connect Inoreader API without Proxy using UserScripts.

Disclaimer: Netlify Edge Function has Quota, so CORS Proxy may stop if it determines that usage is too high.

5 GB / 1 TB bandwidth
58 / 25,000 build minutes
0 / 2M edge function invocations
image

azu added a commit that referenced this issue Jul 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant