Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
Vue Production issue with Express

I'm trying to install SSR on my current Vue app, and for this I'm using the vue-plugin-ssr extension. I want to run it with express, so I created a new file called server.mjs and have this:

import express from "express";
import { createServer as createViteServer } from "vite";
import { renderPage } from "vite-plugin-ssr";

async function createServer() {
  const app = express();

  // Create Vite server in middleware mode and configure the app type as
  // 'custom', disabling Vite's own HTML serving logic so parent server
  // can take control
  const vite = await createViteServer({
    server: { middlewareMode: true },
    appType: "custom",
  });

  // use vite's connect instance as middleware
  // if you use your own express router (express.Router()), you should use router.use
  app.use(vite.middlewares);

  app.get("*", async (req, res) => {
    // `renderPage()` can also be used in serverless environments such as
    // Cloudflare Workers and Vercel
    const { httpResponse } = await renderPage({ url: req.url });
    res.send(httpResponse.body);
  });

  app.listen(3000);
}

createServer();

So this actually works for dev, when I run node server.mjs, but neither client or server folder has an index.html file, so how can I run this on production actually? Only what I'm doing is to set the folder on nginx to path/dist/client, do I need to do something else?

btw as a response on production I have only 403 forbbiden.

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

You need to run the client and ssr build process as demonstrated in Vite's documentation and then:

Move the creation and all usage of the vite dev server behind dev-only conditional branches, then add static file serving middlewares to serve files from dist/client

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!