capri-js / capri

Build static sites with interactive islands
https://capri.build
MIT License
200 stars 5 forks source link

SSR build for vue not output server side #36

Closed xgenvn closed 1 year ago

xgenvn commented 2 years ago

Expect:

Actual:

Logs

fgnass commented 2 years ago

This looks like a regression in vue-router@4.1.x. When I downgrade to vue-router@4.0.x I get the expected result.

It can be fixed by changing the following line in main.server.ts:

// instead of
router.push(`http://127.0.0.1${url}`);
// do this
router.push(url);

With this change unfortunately, the handling of a base path other than / no longer works.

xgenvn commented 1 year ago

@fgnass Besides the issues on vue-router, a bit off-topic, can we serve from the server-side like node dist/main.server.js instead of just serving dist as static files? I saw the vite output included the main.server.js, it seems capri-js dehydrate the server entry into the static generator pipeline for static outputs. Is that correct?

fgnass commented 1 year ago

I'm currently working on proper SSR support in the next branch. The repo already contains two examples, one for Vercel and one for Cloudflare workers: https://github.com/capri-js/capri/tree/next/examples

For a simple Node server something like this should work:

import capri from "@capri-js/vue";
import react from "@vitejs/plugin-vue";
import { defineConfig } from "vite";

export default defineConfig({
  plugins: [
    vue(),
    capri({
      prerender: false, // can also be a function to selectively prerender pages
      target: {
        async build({ ssrBundle, fsutils }) {
          fsutils.copy(ssrBundle, "/path/to/somewhere.js");
        }
      },
    }),
  ],
});
xgenvn commented 1 year ago

@fgnass thank you for the response, I will check the branch. Close the ticket for this moment.

eric-burel commented 1 year ago

I seem to have the same issue with React and latest version, only after a build, I can share the private repo (it's my experiment with Plasmic) if needed

fgnass commented 1 year ago

Hi @eric-burel, sorry for the late reply. I just did a basic check with the current React template which uses react-router-dom 6.3.0, and it worked:

npm init capri my-react-app -- -e react
cd my-react-app
npm run build
npm run preview

If you share your repo I'll take a look!

eric-burel commented 1 year ago

Hey @fgnass, I've invited you to the repo. I was already using react-router-dom 6.3.0 so I don't know what happens.

I am not stuck in anyway as I can restart from scratch but if you manage to reproduce the issues, this may help you figure out some bugs.

It's private only because I was testing out Plasmic and not yet sure of which API key is public or not (the one in the repo is public according to Plasmic team), so feel free to reuse this code if you want to create a Plasmic starter.