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

  1. Install the live server. –

    NPM global installation

    npm install -g live-server

  2. Go to the project folder

    npm init

    Build on the project to get package.json
  3. rightpackage.jsonconfigure

{  "name": "jg_control"."version": "1.0.0"."description": ""."main": "index.js"."scripts": {    "test": "echo \"Error:&nbspno&nbsptest&nbspspecified\" &&&nbspexit&nbsp1"."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!!