nuxt-hub / core

Build full-stack applications with Nuxt on CloudFlare, with zero configuration.
https://hub.nuxt.com
Apache License 2.0
993 stars 56 forks source link

Server "Api" routes missing #339

Open jswhisperer opened 1 month ago

jswhisperer commented 1 month ago

Describe the bug Server "Api" routes missing

https://nuxt-app-gregpalaci.nuxt.dev/ all good https://nuxt-app-gregpalaci.nuxt.dev/api/books MIA

codebase https://github.com/gregpalaci/nuxty-book MIA (https://github.com/gregpalaci/nuxty-book/blob/main/server/api/book/%5Bisbn%5D.ts)

Expected behavior API exists

atinux commented 1 month ago

Where do you deploy your project and with what command?

jswhisperer commented 1 month ago

npx nuxthub deploy

jswhisperer commented 1 month ago

Trying some hacking but feels dirty, can I keep the (dynamic) server routes, server rendered on nuxt hub?

import data from "./prisma/seeds.json";
const bookAPI = Object.fromEntries(
  new Map(data.map(({ isbn }) => [`/api/book/${isbn}`, { prerender: true }]))
);

nuxtConfig....

routeRules: { ...bookAPI, "/api/books": { prerender: true, cors: true }, },



Also tried the experimental.. `defineRouteRules({ prerender: true });`
atinux commented 4 weeks ago

By looking at the console it seems you have a 500 on your API route

CleanShot 2024-10-26 at 09.31.23@2x.png
jswhisperer commented 4 weeks ago

Thank you so much for taking the time to debug! I know you're a busy guy (we met at a meetup before dotjs in an opera house I think / Paris)

I think I need to rephrase my question, does NuxtHub support the node + Server/ routes as a hybrid app? If so what are the settings I need to do, ssr : false I assume?

atinux commented 4 weeks ago

NuxtHub support hybrid rendering by default, no need to set ssr: false 🙂

atinux commented 4 weeks ago

we met at a meetup before dotjs in an opera house I think / Paris)

I don't remember well but I do hope we will meet again :)

atinux commented 4 weeks ago

Re-opening as the issue might be related to Prisma

oritwoen commented 3 weeks ago

I don't know if it's related, but when using Drizzle after deploys I also have 500.

On localhost even with remote it works very well without errors.

Zrzut ekranu z 2024-10-28 09-43-57

jswhisperer commented 3 weeks ago

I think you are correct it's a prisma issue.

Cannot run exec or something.

Prisma is so finicky.

jswhisperer commented 3 weeks ago

Haven't tested but wondering is it because I'm using SQLite with a local file, maybe there is a permissions issue.

cc @oritwoen are you using drizzle with sqlite or remote (real) db?

oritwoen commented 2 weeks ago

Real database from Cloudflare using remote @jswhisperer On dev, i.e. nitro node preset, it works perfectly. With cloudflare-pages preset, something is clearly building incorrectly or pollyfils is missing.

jswhisperer commented 2 weeks ago

Super happy to test, I thought cloudflare-pages was required with nuxt-hub I managed to remove nuxt-hub and also deploy successfully . I'm ok to close this but is there documentation or how does one adjust the presets please.

jswhisperer commented 2 weeks ago

Real database from Cloudflare using remote @jswhisperer On dev, i.e. nitro node preset, it works perfectly. With cloudflare-pages preset, something is clearly building incorrectly or pollyfils is missing.

Happy to close, could you specify how to change the presets... I didn't edit anything and it ran cloudflar-pages as a preset. My solution utimateley was to remove nuxt-hub and deploy elsewhere but not ideal obviously! :)

Article https://dev.to/jswhisperer/i-will-refuse-live-coding-interviews-from-now-on-3mfh heres the code if you want a peak https://github.com/gregpalaci/nuxt-demo-books and a preview https://lambent-fenglisu-27a5c4.netlify.app/