Is Vue.js Incompatible With Serving POST Requests? Is Vue.js Incompatible With Serving POST Requests? express express

Is Vue.js Incompatible With Serving POST Requests?


Vue Router is not receiving a (GET) request and responding, it is simply reading the current URL and inserting the corresponding component. So in short, no, there is no POST request handler... I'd argue it's not even handling GET requests either, just reading the URL which looks like a GET request.

If you are trying to POST between pages inside your app, Vuex is what you want.If you are trying to POST to your app from outside, having an actual server listening for requests which you can ping will be easier (ie Express).

There may be a way to use Axios to do this from your app. It can listen to responses from POST requests, so if it were listening I don't see why it couldn't receive. However, I suspect you'd have to listen to a port from the machine where your app is running which would be a major security issue (if a client's browser/OS/Antivirus even let you).


It's been nearly two weeks since I posted this question, but I didn't even post the question until I'd been struggling with the problem on my own for a week. I finally came to a solution after much head-desking and more dead ends than it would be healthy for my blood pressure to recount. Here it is:

  1. Deciding perhaps my best bet was to look at the vue-cli source code, I happened to notice it includes documentation
  2. The README.md file under docs/config is a bit sparse-looking in what it says about the devserver option, but it also mentions that All options for webpack-dev-server are supported. Ooh.
  3. The Webpack documentation shows a devserver.before option that allows you to access the Express app object and add your own custom middleware to it
  4. This allows you to intercept the POST and redirect it as a GET
  5. Which this guy, who was having the exact same problem as I was, ultimately did. (Note that he used devserver.setup, which does the same thing, but is deprecated in favor of devserver.before.) In vue.config.js, include
devServer: {    before: function(app) {        app.post('/about.html', function(req, res) {          res.redirect('/about.html');        });    },}