Luis Filipe
Luis Filipe

Reputation: 8708

How to host Webpack DevServer in a custom path

I am trying to configure webpack devserver to run in http://localhost:8080/myProject

instead of the root path localhost:8080

I already tried to configure

public: 'https://localhost:8080/myProject',

and

publicPath: '/myProject/'

settings but I can't make it work.

I also tried to play with the proxy settings but that seems wrong.

The reason why i need this change it's because the api server sends a cookie with path=/myProject.

What am I missing?

Upvotes: 2

Views: 932

Answers (1)

Michael Yurin
Michael Yurin

Reputation: 1060

Are you trying to emulate some API or do you want to get your front-end app at /myProject? If you want front-end at /myProject you don't need to edit a devserver, you just need to configure output in webpack.config.js:

output: {
  publicPath: '/myProject',
},

For emulating API you can use onBeforeSetupMiddleware in webpack.config.js:

devServer: {
  port: 3000,
  https: true,
  onBeforeSetupMiddleware: function (devServer) {
    devServer.app.get('/myProject', function (req, res) {
      res.json({
        message: 'some data from API'
      });
    });
  },
},

Upvotes: 1

Related Questions