When developing HTML static pages locally, you encounter cross-domain problems with requesting interfaces
Previously developed with VUE, the project cooperated with NGINx to solve cross-domain proxy forwarding.
scenario: Using native HTML+JS development, native HTML orgin null encountered cross-domain problems.
The solution
Use live-server to deploy local HTML projects on local servers and combine Node to solve cross-domain problems.
steps
- Install the live server. –
NPM global installationnpm install -g live-server
- Go to the project folder
npm init
Build on the project to get package.json - right
package.json
configure
{ "name": "jg_control"."version": "1.0.0"."description": ""."main": "index.js"."scripts": { "test": "echo \"Error: no test specified\" && exit 1"."start": "Live - server - open = / index html - port = 7777 & NBSP - proxy = / transpond: http://192.168.20.57:18101/transpond" }, "author": ""."license": "ISC"}Copy the code
Proxy = / transpond: http://192.168.20.57:18101/transpond “to the address of the agent in the past
4. Run NPM run start
Success!!