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
Hello, I’m Allie!
You could have your Worker redirect based on the protocol?
Register
RegisterOP11mo ago
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?
Register
RegisterOP11mo ago
@HardlyWorkin' I have also created a Page Rule (after reading some SO post) Do you think this is the right direction?
No description
Register
RegisterOP11mo ago
After I did this, I get this:
No description
Register
RegisterOP11mo ago
in my "Pages" project, I have this file: /functions/api/submit.ts
import EventContext from "@/EventContext";

export async function onRequestGet(ctx: EventContext) {
console.log("submit get");
return Response.json({result: "submit get"});
}

export async function onRequestPost(ctx: EventContext) {
console.log("submit post");
return Response.json({result: "submit post"});
}
import EventContext from "@/EventContext";

export async function onRequestGet(ctx: EventContext) {
console.log("submit get");
return Response.json({result: "submit get"});
}

export async function onRequestPost(ctx: EventContext) {
console.log("submit post");
return Response.json({result: "submit post"});
}
Register
RegisterOP11mo ago
Since I am working with Pages I assumed I'd use Page rules?
No description
Hello, I’m Allie!
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 deployment
Register
RegisterOP11mo ago
Alright - are you suggesting I move my API logic from my Pages project and into its own "Worker"?
Hello, I’m Allie!
No, you can keep it in Pages. In fact, this shouldn't require any changes to configuration.
Register
RegisterOP11mo ago
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
Register
RegisterOP11mo ago
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)
No description
Register
RegisterOP11mo ago
So from my perspective, I am using "Pages" and I have "Functions" inside my Pages project
Register
RegisterOP11mo ago
No description
Register
RegisterOP11mo ago
so what am I supposed to do to get this /api/submit route working with HTTP?
Hello, I’m Allie!
Do you only want it to apply to /api/submit, or to the entirety of /api?
Register
RegisterOP11mo ago
only /api/submit it's the only route in my API that needs HTTP I need to be able to POST to it
Hello, I’m Allie!
Wild guess but this might work? Don't remember if you can use a specific route with next()...
Hello, I’m Allie!
The indentation is completely screwed, sorry
Register
RegisterOP11mo ago
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 it
Register
RegisterOP11mo ago
Could it be something here? _redirects?
No description
Walshy
Walshy11mo ago
pages doesn't handle http/https
Hello, I’m Allie!
Doesn't the pages.dev zone force HTTPS?
Walshy
Walshy11mo ago
the dev tld forces https
Hello, I’m Allie!
Or the auto upgrade
Walshy
Walshy11mo ago
but custom domains should take priority
Hello, I’m Allie!
Are you on a custom domain?
Register
RegisterOP11mo ago
Yes
No description
Register
RegisterOP11mo ago
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
Register
RegisterOP11mo ago
No description
Register
RegisterOP11mo ago
No description
Register
RegisterOP11mo ago
Is this it?
Hello, I’m Allie!
No, it is in SSL/TLS -> Edge Certificates
Register
RegisterOP11mo ago
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?
No description
Register
RegisterOP11mo ago
Whats the difference between: Always Use HTTPS and Automatic HTTPS Rewrites ?
Register
RegisterOP11mo ago
No description
Hello, I’m Allie!
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 HTTPS
Register
RegisterOP11mo ago
Just double checking - I should disable them both?
Hello, I’m Allie!
Use a Configuration Rule instead, so that it only affects /api/submit
Register
RegisterOP11mo ago
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?
Hello, I’m Allie!
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...
Register
RegisterOP11mo ago
hmmm i think its still redirecting
Register
RegisterOP11mo ago
No description
Register
RegisterOP11mo ago
No description
Hello, I’m Allie!
Do you have cache disabled? 301s are usually cached a while
Register
RegisterOP11mo ago
No description
Register
RegisterOP11mo ago
Yes I have it disabled :)
Hello, I’m Allie!
That will only match if you are already using HTTP
Register
RegisterOP11mo ago
should I make it say https? and yes the (very old) game is explicitly using HTTP
Hello, I’m Allie!
No, just filter by URI path
Register
RegisterOP11mo ago
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
Register
RegisterOP11mo ago
oo ok
Register
RegisterOP11mo ago
@HardlyWorkin'
No description
No description
No description
Register
RegisterOP11mo ago
:'(
Hello, I’m Allie!
What is it redirecting to?
Register
RegisterOP11mo ago
back to https://bldb... which redirects back to http://bldb... etc
Hello, I’m Allie!
Hm, ok...
Register
RegisterOP11mo ago
No description
Hello, I’m Allie!
Checking rn
Register
RegisterOP11mo ago
No description
Register
RegisterOP11mo ago
@HardlyWorkin' any updates? Kinda dead in the water at the moment :s
Hello, I’m Allie!
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
Register
RegisterOP11mo ago
Shoot. Thanks for trying
Want results from more Discord servers?
Add your server