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

329
Views
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 answers
Answer question

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 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!