Hi,
I’m trying to make a blog hosted on blog.aitranscriber.tech
appear on aitranscriber.tech/blog
. I’ve gotten the GET requests to be routed properly and as you can see on the latter link, the page appears correctly.
I’m unable to route the POST requests though. The forwarding behavior I’m trying to achieve works well on Netlify which I’m using to point phreakyphoenix.tech/blog
to blog.phreakyphoenix.tech
. The relevant part of the netlify.toml file is below
[[redirects]]
from = "/blog/*"
to = "https://blog.phreakyphoenix.tech/:splat"
status = 200
[[redirects]]
from = "/_next/*"
to = "https://blog.phreakyphoenix.tech/_next/:splat"
status = 200
[[redirects]]
from = "/api/*"
to = "https://blog.phreakyphoenix.tech/api/:splat"
status = 200
[[redirects]]
from = "/js/*"
to = "https://blog.phreakyphoenix.tech/js/:splat"
status = 200
[[redirects]]
from = "/newsletter/*"
to = "https://blog.phreakyphoenix.tech/newsletter/:splat"
status = 200
[[redirects]]
from = "/ping/*"
to = "https://blog.phreakyphoenix.tech/ping/:splat"
status = 200
[[redirects]]
from = "/_axiom/*"
to = "https://blog.phreakyphoenix.tech/_axiom/:splat"
status = 200
I ideally want to handle the post requests with transforms (basic forward with status 200), and I’ve a rule with the expression
(http.request.method eq "POST" and http.host eq "aitranscriber.tech")
set to dynamically rewrite the path to
concat("blog.aitranscriber.tech", http.request.uri.path)
On aitranscriber.tech/blog
, when I make a POST request to the below URLs, I get an error 500
https://aitranscriber.tech/ping/data-event
https://aitranscriber.tech/_axiom/web-vitals
https://aitranscriber.tech/ping/gamp
https://aitranscriber.tech/api/collect
-
https://aitranscriber.tech/ping/view
and on the linkhttps://aitranscriber.tech/api/newsletter/subscribe
, I get the 500 error with the messageUncaught (in promise) SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
I just want them to be forwarded to https://blog.aitranscriber.tech+path
These errors don’t appear on blog.aitranscriber.tech
or on phreakyphoenix.tech/blog
or blog.phreakyphoenix.tech
, which is hosted with netlify and has the redirects mentioned above. You can also take a look at the errors by browsing the sites directly.
Do note aitranscriber.tech
, the main site itself is on an Cloudflare Tunnel and since my server is off right now, you might see an error 1033, which is not related to this issue and this issue appears even when the Cloudflare Tunnel is active and the site is live.
In a gist:
- I want the POST requests to work with transforms just the way it works on Netlify, I’m no expert on routing and might be making a mistake in my Dynamic rewrite, please help me out if that’s the case.
- Else I want to implement the same with workers.
Some additional notes:
- My worker file, though not relevant to post requests is visible
https://github.com/phreakyphoenix/misc/blob/master/worker.js
, I did try to implement a MethodNotAllowed, and if I turn my transform off, then I go get the 405 error as defined in the status of the MethodNotAllowed. I couldn’t figure out how to meaningfully use the worker to do a simple 200 status forward. - I also tried redirects, with status code 301 and 302, same expression and rewrite, which gives me a CORS error, complaining about cross-site requests not being allowed.
Solving this hurdle will help us host our blogs on subdirectories instead of subdomains with platforms like Hashnode, and I’d really appreciate the Cloudflare Community’s help in doing this.
PS: This is my first post, I couldn’t seem to post with any links so all links are backticked as pre-formatted text, thanks in advance for your help everyone.