Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

330
Visualizações
Serve Vue,.js Pages with Express post with parameters

I've an web application that can render sites embeded. The problem is that this site only send POST requests.

So i thought about serving it using express, then i searched a little here i got the following code to serve it, listening to all GET requests as vuetify pages:

const express = require('express');
const path = require('path');

const hostname = 'localhost';
const port = 3000;

const app = express();
app.use(express.static(path.join(__dirname, 'dist')));

app.get('*', (req, res) => {
 res.sendFile(__dirname, '/dist/index.html');
});

app.listen(port, hostname, () => {
 console.log("Listening at http://%s:%s/", hostname, port);
});

Then I thought to add a post method to, receiving the parameters the page sends:

const express = require('express');
const path = require('path');

const hostname = 'localhost';
const port = 3000;

const app = express();
app.use(express.static(path.join(__dirname, 'dist')));

app.get('*', (req, res) => {
 res.sendFile(__dirname, '/dist/index.html');
});
app.get('*', (req, res) => {
 res.sendFile(__dirname, '/dist/index.html');
});

app.post('/data', (req, res) => {
 const id = req.body.id;
 res.sendFile(__dirname, '/dist/index.html');
});

app.listen(port, hostname, () => {

 console.log("Listening at http://%s:%s/", hostname, port);
});

How do i pass this argument to vue?

Is this the best way to serve vue with a post request?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You are only sending the index.html file, there are other important files generated by vue.js.

In the following file I have a working middleware to serve a vue application which is built in ../../../frontend/dist/.
https://github.com/marekvospel/libregifts/blob/next/apps/backend/src/router/index.ts

The only important thing is the 2 middleware functions. You can replace the '/api' condition with a method check.

if (req.originalUrl.startsWith('/api')) next()
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda