Is it possible to deploy JStack to Cloudflare pages + workers
Is it possible to deploy JStack to Cloudflare pages + workers? Has somebody tried that? Could you provide a documentation or guidance on how to do it
UPD: I figured out that it's possible, but I ran into an issue while implementing it. According to the documentation, cloudflare pages need to use Edge Runtime on the server side, but my PostgreSQL requires Node.js Runtime. So I'm stuck with this runtime conflict.
I haven’t tried deploying JStack to Cloudflare Pages + Workers myself, but I can share something that might help.
Cloudflare Pages defaults to the Edge Runtime, which doesn’t support Node.js features like PostgreSQL access. To get around this, you can use OpenNext, which supports the Node.js runtime on Workers.
Cloudflare actually recommends OpenNext over their own next-on-pages adapter: Blog post
Might be worth checking out!
Am going to actually attempt this today. I like how JStack is structure compared to nextjs, and opennextjs.
My worries with JStack after watching and reading the docs are mainly I prefer my frontend and backend/apis on the some hosting localhost:3000/ frontend localhost:3000/api backend api, localhost:3000/admin backend dashboard. I have no interest in having them separate
Because it's pointless, tiresome and expensive for someone like me who is broke having to host the backend on cloudflare workers and frontend on vercel I like everything in one directory one hosting bucket and kinda started liking cloudflare more with exception of not supporting nodejs runtime full but with promises to support it.
I'll try out JStack today for a platform am trying to build and if it works fine I'll write back here the steps and then proceed to attempt to create a headless cloudflare supported cms. Nodejs runtime with it.
Hi @iamyegor,
I faced a similar issue when trying to deploy JStack fully on Cloudflare, so I wanted to share what worked for me—hope it helps!
-
Frontend on Cloudflare Pages: I made the frontend fully static by setting
output: "export"innext.config.mjsand removing the backend API routes (src/app/api). Also, I addedNODE_VERSION=22to the Pages environment variables because Next.js needs a newer Node version. -
Backend on Cloudflare Workers: For the backend, I deployed it to Workers with Node.js compatibility by adding
"compatibility_flags": ["nodejs_compat"]in thewrangler.jsoncorwrangler.toml. This seemed to let the backend talk to PostgreSQL without issues.
This way, I was able to avoid the Edge Runtime’s Node.js limitations by splitting frontend (static) and backend (Node.js) deployments within Cloudflare.
Also, don’t forget to update the baseUrl in src/lib/client.ts for local development, something like this:
import type { AppRouter } from "@/server";
import { createClient } from "jstack";
export const client = createClient<AppRouter>({
baseUrl: `${getBaseUrl()}/api`,
});
function getBaseUrl() {
if (process.env.NODE_ENV === "production") {
return process.env.NEXT_PUBLIC_WORKERS_URL;
}
return `http://localhost:8080`;
}
If I misunderstood anything or if you want me to explain more or share configs, just let me know! I’m happy to help.