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.

Can't config proxy in configureWebpack

See original GitHub issue

Description

I am following config devServer proxy in vuecli

Steps to reproduce

  • Add proxy to webpack config
configureWebpack: {
    devServer: {
      proxy: {
        '/.netlify/functions/**': {
          target: 'http://localhost:9000',
          changeOrigin: true,
          secure: false,
          pathRewrite: {
            '^/\\.netlify/functions': ''
          }
        }
      }
    },
  },

Expected result

Should change host

Actual result

No change host

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
kara-toddcommented, Jun 18, 2019

I wasn’t able to get the webpack devServer proxy to work, but I’m not 100% sure how the gridsome internals worked. Since it looks like express is used internally, I used a similar approach to creating a proxy in gatsby. This seemed to resolve the issue for me…

Steps:

  1. yarn add -d http-proxy-middleware or npm install http-proxy-middleware --save-dev
  2. Create gridsome.server.js in the project root (same directory as gridsome.config.js)
  3. Add the following code:
var proxy = require("http-proxy-middleware");

module.exports = function(api) {
  api.configureServer(app => {
    app.use(
      "/.netlify/functions/",
      proxy({
        target: "http://localhost:9001",
        pathRewrite: {
          "/.netlify/functions/": ""
        }
      })
    );
  });
};

I forgot to mention… I start the proxy on 9001 because it looks like something else is running on 9000 … not sure what that is… 😛

4reactions
Sergixcommented, Jun 6, 2020

@BobDempsey

The http-proxy-middleware package has since been renamed the proxy method to createProxyMiddleware. You should now import the method like this:

const { createProxyMiddleware } = require('http-proxy-middleware')
Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack dev server proxy settings can't customized ... - GitHub
Attempt to override proxy settings in vue.config.js with any setting that doesn't jive with prepareProxy's validators or createProxyEntry ...
Read more >
Configure webpack-dev-server to play nice with different ...
I want to configure webpack-dev-server to proxy my existing site served from http://website.dev and proxy its' javascript assets which would be served from ......
Read more >
devServer proxy(in vue.config.js) not working - Get Help
I encountered this problem, too. devServer proxy not working What should i do? vue.config.js exists in root dir of vue project.
Read more >
DevServer - webpack
This option allows you to allowlist services that are allowed to access the dev server. webpack.config.js module.exports = { //... devServer: ...
Read more >
Configuration - Nuxt
The axios-module cannot be used in nuxt.config.js . You will need to import axios and configure it again. Further configuration.
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