[this paper reference address to work to Jason_hu log 2015/04/15 and my.oschina.net/jdragon/blo…).

The proxy parameter of HTTP-Server component in NodeJS is used to simulate the proxy proxy of front-end and back-end

  • For example: we front-end request API, can not write dead URL:"http://10.10.10.10:7000", because the IP may change at any time, or the corresponding server may be different in different test environments (SIT,UAT,PRO).
  • We need to go throughnginxTo proxy requests/apis… …
$.ajax({url: "/ API /draw/m", content: "application/json"}) location /api { proxy_pass http://TEST01:7000/api; ... ... ... /etc file, cat it and add the mapping 10.10.10.10 TEST01 to itCopy the code
  • The directory structure for our local project is as follows: the main content is in the SRC directory
./src
	./css
	./js
	index.html
  	demo.html
package.json
Copy the code

Http-server is a tool in the NodeJS framework, itself written in javascript. Install NPM install http-server-g

  • At first I thought I would open the project with vscode, straight awaynpx http-serverYou can run. You shouldcd srcnpx http-serverTo run (my local SRC directory structure. Index and so on under SRC)
  • When I’m done with that,/api/draw/mWill be submitted to the404The path is wrong, of course, because we have not configured the URI of the request locally to forward it to another Web server for processing to achieve the purpose of proxy proxy
  • npx http-serverThis is suitable for no proxy

Http-server -p starts with -p and you can use http://127.0.0.1:8080 to access your page

  • First, the server test environment is already deployed on a test server.http://testserver/apiOr you know the exact IP addresshttp://10.10.10.10:7000
  • When the HTTP-server detects that the requested address does not exist locally, it forwards the REQUEST URI to another Web server for processing. After receiving the result, the local server responds to the requester to achieve the purpose of proxy proxy
CD SRC Run the http-server-p "http://testserver" or http-server-p "http://10.10.10.10:7000" command.Copy the code
  • http-server -PAfter that, whenever you perform the current page call to the API, you’ll see the vscode console pop up with some columns of logs under the tool
[Sat Nov 28 2020 21:27:56 GMT+0800 (GMT+08:00)] "GET/API /draw/m" Win64; X64) AppleWebKit / 537.36 (KHTML, Like Gecko) Chrome/87.0.4280.66 Safari/537.36" [Sat Nov 28 2020 21:28:12 GMT+0800 (GMT+08:00)]" "Mozilla / 5.0 (Windows NT 10.0; Win64; X64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36"Copy the code

conclusion

React QQ group:788023830 —- React/Redux - Old underground hero

Front-end COMMUNICATION QQ group:249620372 —- FRONT - END - JS FRONT END

(Our mission is, for overtime, for baldness… , look up to the big guy), I hope friends to study together