Live-server starts node service locally to solve cross-domain problems

1. Initialize node and build package.json

 NPM install live-server globally

npm install -g live-server

 Run cmd in the current project folder:

npm init -y

At this time, a package.json file will be generated in the root directory.

 2. Generate proxy script

Create a new build.js file in the root folder (the name can be customized)

var liveServer = require("live-server");

var params = {
    port: 8081,
    host: "localhost",
    open: false,
    root: "src",
    file: "index.html",
    wait: 1000,
    logLevel: 2,
    proxy: [['/api','http://192.168.1.121:7000/api']]
};

liveServer.start(params);

3. Run the node startup script

npm run dev

Executing dev is equivalent to executing the build.js file

Guess you like

Origin blog.csdn.net/weixin_53474595/article/details/131985984