0

So I am passing a data to my express route and the route will generate a pdf. This is my code:

Vue Method:

this.$http.post('http://localhost:3030/pdf', user_data).then(function(response) {
   console.log('Success', response)
}, function(error) {
   console.log('Error', error)
})

http://localhost:3030/pdf

res.render('pdf', {
    personal_information: req.body.personal_information
}, function (err, html) {
    //generate pdf
    pdf.create(html).toBuffer(function (err, buffer) {
        if (err) {
            console.log(err)
            next()
        } else {
            var pdfBuffer = new Buffer(buffer)
            res.setHeader('Content-disposition', 'inline; filename="test.pdf"');
            res.setHeader('Content-type', 'application/pdf');
            res.send(pdfBuffer)
        }

    });
});

The code actually works, it is able to generate a pdf file that can be downloaded also but I am not getting a success response in my vue promise. This is what I get

enter image description here

Is there a way to handle this?

If your answer will include a cors issue, I just want you to know that I am using feathersjs and cors package is already installed.

const cors = require('cors');
app.use(cors())

The thing is when I change the content-type, I get a success response but it won't let me download the pdf.

Marek Urbanowicz
  • 12,659
  • 16
  • 62
  • 87
wobsoriano
  • 12,348
  • 24
  • 92
  • 162

1 Answers1

-1

A super-simple method to enable CORS is to use the cors package.

const cors = require('cors');

const app = express();
app.use(cors());

I'd recommend reading the package's documentation to know more about how to configure it securely.

GPX
  • 3,506
  • 10
  • 52
  • 69