Sunday 22 September 2019

Linking Vue.js and Express behind a Nginx reverse proxy

I'm very new to the node world and I am slightly struggling to get my vue.js frontend to communicate with my express backend. Locally I can do it no problem, but I am stuck trying to do it on my server.Nginx is serving as a reverse proxy, my current config has www.x.com/upload traffic sent to the express server and all other traffic sent to the vue server. I am using dropzone to upload the files.All data is sent when I upload according to the network tool in chrome, but the file doesn't appear in the express server and dropzone never shows 'upload success' like it would when run locally. I'm not really sure what's wrong, data is being sent to the right location, and I don't know why express wouldn't handle it properly. It must be a config issue since everything runs locally but I am a bit lost. Any help would be very much appreciated.My current express index.js is simplyconst express = require('express'); const multer = require('multer'); const cors = require('cors'); const app = express(); app.use(cors()); const upload = multer({ dest:'./uploads/' }) app.post('/upload',upload.single('file'), (req, res) => { res.json({file:req.file}); }); app.listen(3000,()=> console.log("Running on localhost:3000")); Thanks!

Submitted September 23, 2019 at 12:00AM by Macscroge

No comments:

Post a Comment