question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What problem does this feature solve?

devServer.proxy cannot be used to proxy root requests now. It is very usefull when your vue app is under some php project.

What does the proposed API look like?

Webpack DevServer can be set to proxy root requests too: https://webpack.js.org/configuration/dev-server/#devserverproxy with this config:

module.exports = {
  //...
  devServer: {
    index: '', // specify to enable root proxying
    host: '...',
    contentBase: '...',
    proxy: {
      context: () => true,
      target: 'http://localhost:1234'
    }
  }
};

but now this config throw error:

When `proxy` in package.json is an object, each `context` object must have a `target` property specified as a url string

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:9
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
padinkocommented, Mar 7, 2019

This config will not proxy the root request…

here is my config:

    devServer: {
        index: '',
        host: process.env.SERVE_DOMAIN,
        port: process.env.SERVE_PORT,
        proxy: {
            '^/': {
                target: process.env.APP_URL,
                ws: true,
                changeOrigin: true,
            },
        },
    },

problem is when I open http://SERVE_DOMAIN:SERVE_PORT (i.e. http://localhost:8080 ) dev server returns: Cannot GET /

instead of pass proxy to APP_URL

If you want to proxy this request too, you need to pass index: '' and context function which return true/false, when server should proxy request.

vue-cli don’t allow to pass context function, that’s the problem

EDIT: you can check example here https://webpack.js.org/configuration/dev-server/#devserverproxy search root proxying

5reactions
probilcommented, Jul 16, 2019

@padinko Solved it this way (for now)

const proxyMiddleware = require('http-proxy-middleware')

const PROXY = 'http://localhost:3000'

module.exports = {
  devServer: {
    index: '',
    serveIndex: false,
    historyApiFallback: false,
    progress: false,
    proxy: {
      '^/': {
        target: PROXY,
        ws: false,
        changeOrigin: true
      }
    },
    staticOptions: {
      redirect: false
    },
    after: app => app.use('/', proxyMiddleware(PROXY))
  },
}

Not the best way but at least it works fine in my case

Read more comments on GitHub >

github_iconTop Results From Across the Web

Proxy to sites that expect to be at root URL? - Server Fault
(Normally a proxy only rewrites HTTP headers/responses). mod_substitute in apache 2.2. I haven't tested if it stacks well with mod_proxy and ...
Read more >
Behind a Proxy - FastAPI
That demonstrates how the Proxy (Traefik) uses the path prefix and how the server (Uvicorn) uses the root_path from the option --root-path ....
Read more >
nginx location proxy pass forwarding to root URL rather than ...
I am using Nginx as a proxy, example.com is my outward-facing web server with SSL enabled I want traffic coming under ...
Read more >
Reverse proxy redirect to servers based on url root path - Help!
I am new to HAProxy and struggling to understand how things to configure. I have found just one example for Grafana, though I...
Read more >
root proxy url - Technical Documentation - Juniper Networks
Specifies your network's HTTP proxy server, which can submit HTTP requests on the E Series router's behalf to retrieve the root CA ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found