The dev-server of webpack can only match get requests, which will be inconvenient when doing local data.
There are two ways to solve the problem:
1. Join the devServer field in the configuration file
devServe:{ setup: (app) => { //Solve the problem of post not responding ('/goform/**', function(req, res) { (); //Redirect to the corresponding path }); } }
@webpack3.0 and later version setup need to be changed to before
2. Find webpack-dev-server/lib/ in node_modules. In the Server function, add the following code to about 100 lines. To intercept post request. Of course, you have to write the path yourself, or you can write it as above.
('/goform/*', (req, res) => { ('Content-Type', 'text/plain;charset=UTF-8'); let filename = (__dirname,'..','..','..',`public/${}.txt`); (filename, exists => { if(exists) { ((__dirname,'..','..','..',`public/${}.txt`)).pipe(res); }else { (`${}' <- <- Old Tie,You haven't written this interface yet。`); } });
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.