Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question about proxy #1173

Closed
lzl124631x opened this issue Dec 15, 2017 · 2 comments
Closed

question about proxy #1173

lzl124631x opened this issue Dec 15, 2017 · 2 comments

Comments

@lzl124631x
Copy link

lzl124631x commented Dec 15, 2017

Hi,

I'm trying to proxy all requests /api/* to localhost:3000/api/*. No luck for the moment.

According to webpack-dev-server, I tried to add the following snippet in dev object of file config/index.js. But it didn't take effect.

proxyTable: {
      '/api': {
        target: 'http://localhost:3000',
        secure: false,
        changeOrigin: true // No matter this is true or false
      }
    }

The browser kept failing with 404 for API requests e.g. "http://localhost:8080/api/login".

Questions:

  1. How to correctly proxy all requests from localhost/api/*(front-end) to localhost:3000/api/*(back-end)?
  2. I found that I will always land on index.html with arbitrary link e.g. http://localhost:8080/123/abc/!@$#/. Why?
@LinusBorg
Copy link
Contributor

  1. target: 'http://localhost:3000/api',
  2. That's because we have set the historyFallback option of the webpack)dev-server, which is required to make vue-router work in history mode. You can read more about that in the router docs.

For further such general questions, I would recommend to visit forum.vuejs.org or chat.vuejs.org

@lzl124631x
Copy link
Author

lzl124631x commented Dec 15, 2017

Hi @LinusBorg Thanks for your reply!

The first one actually should be target: 'http://localhost:3000' according to dev-server.

My problem was that, after changing the webpack.dev.config.js, I have to ctrl+c to shut down the dev-server and restart npm run dev. The old node application is NOT shut down along with it and occupies port 8080; and the new node application starts at port 8081 (I didn't notice that!). So if I keep visiting localhost:8080 I will get 404 forever; I need to localhost:8081 to get 200.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants