me: Can u build https://github.com/brightmann/Lzbnb on cloudflare?
I cloned it and read through the code. Lzbnb is a full-stack blog, not a static site:
- Next 9.4.1 + React 16, pages router,
getServerSidePropson the post pages - Sign-up / sign-in with sessions, post CRUD, comments
- PostgreSQL via TypeORM (User / Post / Comment tables, migrations, seed data)
That means it can't run as a static export on Cloudflare Workers — it needs a live Postgres database and a Node server running next start for the SSR pages and API routes.
The way to do it is the same as your other full-stack sites (anb, mnb, mvb): host it on this VM with its own Postgres, then put it live at lzbnb.luckypoem.workers.dev through a proxy Worker. One thing to know: the seed data creates a demo user lzb with password 123123, so we'd change that before going live.
Want me to go ahead with the VM route?
me: Yes, build it on the VM
It's live: https://lzbnb.luckypoem.workers.dev
What I did: installed PostgreSQL 16 on the VM with its data in ~/data/lzbnb-pg, ran the migrations, built the app with Node 18, and started it as a service on port 3256. The tunnel hostname lzbnb.mingsea.net and the proxy Worker are in place, so the public address goes through the same front door as your other VM sites.
Verified live: homepage, post list, sign-in and sign-up pages all return 200, and I tested the full flow — sign up, sign in, create a post, see it in the list — then deleted the test data. The database is empty now, so just sign up with your own account; I did not run the seed, so the demo user lzb / 123123 was never created. The site title is still the original author's (刘圳槟的个人博客) — yours to change whenever you like. The GitHub repo is untouched; all the build changes live only on the VM, with a recovery script saved for the next VM replacement.
One thing left: it's not yet covered by the watchdog, so a VM replacement wouldn't auto-restore it until I add it. Want me to add that coverage?
me: yes
Done. Lzbnb is now Step 12 in the watchdog — every 5 minutes it checks that both the Postgres service and the app service are running and that the app answers locally on port 3256, and if anything is down it runs the recovery script.
I also tested that recovery script end to end just now: it re-applied the apt fixes, restarted both services, confirmed no migrations were pending, and the site came back — local and public both 200. So the next VM replacement should bring it back on its own like the other stacks.
me: Where to sign up?
right here https://lzbnb.luckypoem.workers.dev/sign_up .Pick a username and password, and you're in — then "新增文章" at the top of the post list is where you write a new post.
me: I already signed up. Pls close signup.
Closed. The sign-up page now just says 注册已关闭 with a link to log in, and the registration API returns 403 — I tested it with a throwaway attempt and it was rejected, both locally and on the public site. Your account is untouched (still the only user in the database), and sign-in works as before.
me: And the posts order is not as per publishing time. Pls fix it. Make the newest first.
me: And can u make /post support pagination?
Both fixed and verified live.
Order: the list query had no ordering at all, so posts came back oldest first. It now sorts by publish time, newest first — your latest post (中华民族是一个优秀民族吗?) is on top, 战马 at the bottom.
Pagination: the pager was actually already in the template, but it only shows when there's more than one page — and with 10 posts per page, your 6 posts all fit on one page, so it never appeared. I changed it to 5 per page: page 1 now shows the 5 newest, and there's a pager with 上一页 | 1 | 2 | 下一页. Page 2 holds 战马.
The pager itself — the 上一页 | 1 | 2 | 下一页 buttons — was already in the template (hooks/usePager.tsx), I didn't touch that. It just never showed because with 10 per page, your 6 posts fit on one page and it hides itself on a single page. The 10 posts/page→ 5 posts/page change is what made it appear.
me: But if u use neon db as postgresql db, then the blog app doesn't need to install on ur VM,correct?
Half right — Neon would replace the database, but the app itself still needs a Node server somewhere. It can't run on Cloudflare Workers even with Neon, for two reasons:
- The app is Next 9.4.1, too old for OpenNext, which is what puts Next.js on Workers.
- It talks to Postgres through TypeORM's
pgdriver, which opens a raw TCP connection. Workers can only make HTTP requests, so that driver can't connect at all. Neon does have an HTTP driver, but TypeORM can't use it — the whole data layer would have to be rewritten.
So the database could leave the VM, but the app would still need a server. The realistic way to get it off the VM entirely is Vercel + Neon: Vercel runs the Next.js server, Neon holds the data. That would need a few code changes — the database config would have to come from environment variables instead of the ormconfig.json file, and the build would need to run the babel step first.
Want me to move it to Vercel + Neon, or keep it on the VM as it is?
me: Cloudflare workers+neon is ok?
No — not for this app as it is. Two blockers, and Neon only fixes one of them:
Neon solves the database side, since it's Postgres over the internet. But the app side still can't run on Workers:
- Next 9 is too old. OpenNext, the adapter that runs Next.js on Workers, only supports modern Next (15/16). It doesn't work with a 2020-era Next 9 app.
- TypeORM still needs TCP. Even with Neon as the database, the app connects through TypeORM's
pgdriver, which opens a raw TCP connection. Workers can only make HTTP requests, so that connection can't happen. Neon has an HTTP driver, but TypeORM can't use it.
Workers + Neon works fine for apps built for it — a modern Next.js app using Neon's serverless driver, for example. For this blog it would mean a rebuild: upgrade Next across 7 major versions and replace the whole data layer. That's a big job, not a config change.
If the goal is just to get it off my VM without a rewrite, Vercel + Neon is still the path that works as-is.
me: Can u keep vm version untouched and create a 'vercel+neon' version?
The Vercel version is prepared, and the VM version is untouched — I built it in a separate clone from GitHub master, on a new branch called vercel-neon. What's in it:
- Database config reads
DATABASE_URLfrom the environment (Neon) instead of theormconfig.jsonfile - Build pins Node 18 and uses the OpenSSL legacy flag the old webpack needs
- Registration already closed, same as the VM version
I test-built it locally and it compiles clean. The commit is ready to push.
To finish it I need two things from you:
- A GitHub token for brightmann/lzbnb (Contents permission is enough — the branch touches no workflow files). Paste it and I'll push the branch.
- Neon + Vercel setup — I can do both in the browser with your logins: create the Neon project and database, then create the Vercel project on the
vercel-neonbranch with the database URL and session secret. You'd need to be around for the sign-in codes, same as the Vercel reconnect last time.
Once that's done I'll run the migrations on Neon and copy your account and 6 posts over from the VM database, so the new version starts as an exact copy.
me: Sign-in code, u mean sign-in verification code sent from vercel?
Yes — the one-time verification codes that arrive during sign-in.
Concretely, for the Vercel and Neon dashboards I'd sign in with your GitHub account, and GitHub then asks for a 2FA code sent by SMS to your phone — that's the same code you sent me last time for the Vercel reconnect. Vercel itself can also email a code instead, depending on which it asks for.
So when the browser gets to that step, I'd ask you to paste the code here, same as before.
me: So now u haven't created vercel-neon branch?
The branch exists, but only on my machine so far — I created it locally in a separate clone and committed the Vercel + Neon changes to it (commit 2a7cf5c).
It isn't on GitHub yet. Pushing it to github.com/brightmann/lzbnb is the step waiting on your token.
me: my github pat here...
Branch pushed — vercel-neon is now on GitHub.
I've also started the Neon setup in the browser: it'll sign in with your GitHub account and create a new project called "lzbnb". If it hits the sign-in code step, I'll ask you to paste the code here, same as before.
Neon is done: the tables are created and your account plus all 6 posts are copied over — I verified the counts (1 user, 6 posts) and the newest-first order on Neon.
The Vercel project setup is now running in the browser: it'll import the repo on the vercel-neon branch and create an API token for me to set the database URL and session secret. If it hits a sign-in code step, I'll ask you to paste the code.
Vercel sent a 6-digit verification code to brightmann@gmail.com to create the API token. Can you check your Gmail and paste the code here?
me: the code is here...
The Vercel project can't be created: your team "brightmann's projects" has hit the Hobby plan's 200-project limit. The API token is already created, but there's no project to use it with yet.
Your options:
- Upgrade to Pro — paid, raises the limit on this team.
- Create a new team — free, gets its own 200-project limit, but the lzbnb project would live under a separate team.
- Delete a project to free a slot — I'd need you to tell me which one is safe to delete.
- Stop here — leave the Vercel version uncreated for now.
Which way do you want to go?
me: i have Deleted a project on the team "brightmann's projects".
Found it — Vercel rejected Node 18 ("invalid or discontinued"), so the deploy died in 1 second before even installing. I've changed engines to 22.x and committed it locally (79d50e2).
To push it I need the GitHub PAT again — the one from earlier isn't stored. Can you paste the lzbnb PAT once more?
me: the pat...
Pushed — the Node 22 fix is on the branch now, and a new deployment is building on Vercel. I'll check it once the build finishes.
Update: the Node 22 deploy failed for a different reason — the lockfile still pointed at the old Taobao npm mirror, whose certificate has expired. I rewrote all 880 tarball URLs to the official npm registry, pushed it, and a new deployment is building now.
The registry fix had a second half: my host swap produced npmjs URLs in the Taobao path format (/download/), which npmjs 404s — its format is /-/. I fixed all the tarball paths (verified one returns 200), pushed it, and a new deployment is building now.
The scoped fix is pushed (aeffaa1) and a deployment is building now — it survived a service restart mid-command, I verified the push and the deploy both landed.
The Vercel version is live:
Verified just now — homepage loads, /post shows the 6 posts newest-first, 5 per page, page 2 holds 战马, sign-in page works, sign-up is closed, and the API answers 请先登录 when logged out. Your account and posts came over from the VM database, so your login works here too.
Push-to-live works: any push to the vercel-neon branch auto-deploys as production. The VM version is untouched and still live at its own address.
You can revoke both tokens now — the lzbnb GitHub PAT and the Vercel API token "lzbnb-vercel-deploy". Neither is needed anymore.
the blog address is https://lzbnb.vercel.app/
me: Pls change "刘圳槟的个人博客" to "brite's blog" In the homepage.
Done — both versions now say "brite's blog" on the homepage, heading and tab title, verified live:
Posts are untouched on both (6 posts, newest first).
One thing from the VM side: a fourth VM replacement landed mid-work (~10:25) and the database wouldn't start afterwards — the files had ended up owned by the wrong system user after the reinstall. Fixed it, and the posts came back intact.
得到的博客地址:
登录地址: https://lzbnb.vercel.app/sign_in
(我注册的账号-
username: luckypoem
pw: 我设置的密码)
项目地址:
https://github.com/liuzb30/nextjs-blog
https://github.com/brightmann/Lzbnb
相关帖子:
让instinct搭建基于nextjs+postgresql数据库的博客程序nd
No comments:
Post a Comment