javascript - Can the proxyTable proxy request API configured by vue-cli only be used in the development environment? Running build package and putting it on apache does not work
扔个三星炸死你
扔个三星炸死你 2017-06-12 09:31:23
0
4
1566

This is the configuration

proxyTable: {
    '/api': {
      target: 'http://news-at.zhihu.com',
      changeOrigin: true,
      pathRewrite: {
        '^/api': '/api'
      }
    }      
}

Use axios to request data

You can run npm run dev directly, but you cannot get the api after packaging it and putting it on apache

Error reporting

扔个三星炸死你
扔个三星炸死你

reply all(4)
代言

Generally, it is deployed to the formal environment after building. As for what you said about putting it under Apache, the actual request for /api/xxx is also targeted at the Apache Server. So you need to get a rewrite (reverse proxy) for /api for Apache

You can refer to nginx configuration:

location /api/ {
    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded $proxy_add_x_forwarded_for;
    proxy_pass http://news-at.zhihu.com/api/;
}
phpcn_u1582

You see that the proxyTable configuration is written on dev, which proves that this only applies to the dev environment. Essentially, a server dev-server is opened locally, and all requests are forwarded through here.

阿神

You have to run a node web service yourself and then use this in it

给我你的怀抱

This configuration file can be written in a separate config file and referenced in it, and this situation will not occur

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template