Disable https for specific api routes?
I have an API which a very old game is trying to send data to. This old application (circa 2004) cannot handle HTTPS. It must use HTTP.
Is there a way to configure my
wrangler.toml
to specify specific routes for my Pages project to use HTTP instead of HTTPS?65 Replies
You could have your Worker redirect based on the protocol?
Hmmm. Im still a little bit new to the terminology. I thought I was using "Pages" and I thought "Workers" were something else? Or are "Pages" a super set of "Workers" in a way?
@HardlyWorkin' I have also created a Page Rule (after reading some SO post)
Do you think this is the right direction?
After I did this, I get this:
in my "Pages" project, I have this file:
/functions/api/submit.ts
Since I am working with Pages I assumed I'd use Page rules?
No, Page Rules are something else, and are no longer recommended for use
Pages and Workers are two separate products, but they do share some commonalities. You cannot configure your Pages Project with
wrangler.toml
for deploymentAlright - are you suggesting I move my API logic from my Pages project and into its own "Worker"?
No, you can keep it in Pages. In fact, this shouldn't require any changes to configuration.
Thanks! Still unclear on how to use HTTP though.
Do I need to configure a worker rule?
Confused about this because I am using Pages - so the naming is confusing me
This is my project repo. I have my
functions
directory which contains my API and my site
directory which is my static website which Pages automatically deploys for me when I push to my repo. (Lovely btw)So from my perspective, I am using "Pages" and I have "Functions" inside my Pages project
so what am I supposed to do to get this /api/submit route working with HTTP?
Do you only want it to apply to
/api/submit
, or to the entirety of /api
?only
/api/submit
it's the only route in my API that needs HTTP
I need to be able to POST to itWild guess but this might work? Don't remember if you can use a specific route with
next()
...The indentation is completely screwed, sorry
np, I have prettier
Hmm looks like your OnRequest is just checking if its https and redirecting to http. I was under the impression that Cloudflare upgraded to HTTPS before the function is hit?
but tbh I didnt confirm that :o
well I removed the rule to check if I could just use
http
normally (without your suggested code first)
And it looks like it's forcing me to use https by itself
ill apply your suggestion now and see
@HardlyWorkin' I applied your suggestion and it's not working.
I should note that my domain is hosted by Cloudflare
I think theres an HTTPS upgrade happening between the initial request and the function being executed but I dont know where exactly or what to do about itCould it be something here?
_redirects
?pages doesn't handle http/https
Doesn't the
pages.dev
zone force HTTPS?the dev tld forces https
Or the auto upgrade
but custom domains should take priority
Are you on a custom domain?
Yes
I have a CNAME record redirecting to my pages projects dev url
...not sure if that's proper or not but it's allowing me to access my website with the subdomain I want to use
Go to https://dash.cloudflare.com/?to=/:account/:zone/ssl-tls/edge-certificates, and see if
Always Use HTTPS
is set to OnIs this it?
No, it is in
SSL/TLS -> Edge Certificates
Ah yes I found it.
It is on.
I do want HTTPS for all my routes except for
/api/submit
- What will I need to do to ensure HTTPS is forced on the other routes now if I disable this?Whats the difference between:
Always Use HTTPS
and
Automatic HTTPS Rewrites
?
Create a new Configuration Rule here. Set the incoming request match to
URL Path
equals /api/submit
, then set the SSL/TLS mode to Off
Wait
Always use HTTPS redirects HTTP requests to HTTPS. Automaitc HTTPS Rewrites converts all assets on a page to use HTTPSJust double checking - I should disable them both?
Use a Configuration Rule instead, so that it only affects
/api/submit
Ah so I should not touch "Always use HTTPS" or "Automatic HTTPS Rewrites" and I should only create a new configuration rule that matches my
/api/submit
URI?Yes, that should make it so it only applies to that one route.
If you set
SSL/TLS
mode to Off, then it should work?
Though, it may actually cause it to bork itself because it redirects but doesn't support HTTPS...hmmm i think its still redirecting
Do you have cache disabled? 301s are usually cached a while
Yes I have it disabled :)
That will only match if you are already using HTTP
should I make it say https?
and yes the (very old) game is explicitly using HTTP
No, just filter by URI path
what if I have other subdomains though?
I wanted to explicitly use the
bldb.***.com
subdomain
I dont want this rule to trigger for www.***.com
oo ok
@HardlyWorkin'
:'(
What is it redirecting to?
back to
https://bldb...
which redirects back to http://bldb...
etcHm, ok...
Checking rn
@HardlyWorkin' any updates?
Kinda dead in the water at the moment :s
Sorry, not sure. The only surefire way to fix it is probably to disable HTTPS redirects, and then make a separate redirect rule to add it back everywhere except /api/submit
Shoot. Thanks for trying