Skip to content

Cannot run at non-web root URL - remote development #2358

@methodbox

Description

@methodbox
  • Operating System: tested on macOS and remote dev server Debian Stretch
  • Node Version: 12.x
  • NPM Version: 6.9
  • webpack Version: 4.41.2
  • webpack-dev-server Version: 3.9.0
  • Browser: Chrome
  • This is a bug
  • This is a modification request

Code

// webpack.config.js
const webpack = require("webpack");
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");

const config = {
  entry: ["react-hot-loader/patch", "./src/index.js"],
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "[name].[contenthash].js"
  },
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        use: "babel-loader",
        exclude: /node_modules/
      },
      {
        test: /\.css$/,
        use: ["style-loader", "css-loader"]
      }
    ]
  },
  resolve: {
    extensions: [".js", ".jsx"],
    alias: {
      "react-dom": "@hot-loader/react-dom"
    }
  },
  devServer: {
    contentBase: "./dist",
    publicPath: "/testing"
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: require("html-webpack-template"),
      inject: false,
      appMountId: "app"
    })
  ],
  optimization: {
    runtimeChunk: "single",
    splitChunks: {
      cacheGroups: {
        vendor: {
          test: /[\\/]node_modules[\\/]/,
          name: "vendors",
          chunks: "all"
        }
      }
    }
  }
};

module.exports = (env, argv) => {
  if (argv.hot) {
    // Cannot use 'contenthash' when hot reloading is enabled.
    config.output.filename = "[name].[hash].js";
  }

  return config;
};
// additional code, remove if not needed.

Expected Behavior

Setting publicPath should allow the dev server to serve the app at a non-web-root url (i.e. domain.com/urlnamehere vs. domain.com/ ).

This is particularly an issue when working with remote development a la VS Code as the app can't run on root and must be run at an alternate URL. This isn't a technical requirement, but a require in my environment.

Actual Behavior

When using the publicPath, for example, of /testing, and setting Nginx with a proxy_pass, the app is "served" by Nginx, but displays 'Cannot get /testing`.

The built app works with webpack prod build. It serves the app fine. It's the dev server that won't.

Note that on the same server, with the same configuration, I have an Express API running at a non-web-root URL; I am 100% familiar with how to configure this on the Nginx side.

Locally, setting publicPath to /testing simply shows a white page, whether it's accessed at root or at /testing.

**If this isn't the right way to do this, please tell me how I can run the dev server on a remote server at /testing (and not web root). Thanks. **

For Bugs; How can we reproduce the behavior?

Change the publicPath value, watch it not work.

For Features; What is the motivation and/or use-case for the feature?

My primary need is developing remotely. This is 100% necessary as I am working with an iframe which requires same-origin to develop features which target the iframe; bringing the iframe in remotely makes the content of the iframe inaccessible due to browser security.

It's also silly to not be able to use an alternate URL path to serve from.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions