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

Option to disable serveIndex middleware #1745

Closed
1 of 2 tasks
jamesknelson opened this issue Mar 28, 2019 · 6 comments
Closed
1 of 2 tasks

Option to disable serveIndex middleware #1745

jamesknelson opened this issue Mar 28, 2019 · 6 comments

Comments

@jamesknelson
Copy link

  • Operating System: Mac OS 10.14.3
  • Node Version: 11.1.0
  • NPM Version: 6.7.0
  • webpack Version: 4.29.6
  • webpack-dev-server Version: 3.2.1
  • This is a bug
  • This is a modification request

Code

It'd be useful to be able to disable the express serve-index middleware, which generates directory listings when you view a directory that doesn't have an index.html file.

// webpack.config.js
module.exports = {
  // ...
  devServer: {
    serveIndex: false,
  }
}

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

This option is required to be able to do SSR for the root page with webpack-dev-server in an after() middleware using the serverSideRender option, as otherwise an automatically-generated index page will be shown instead.

I'd be happy to put a PR together for this change if it's likely to be accepted.

@alexander-akait
Copy link
Member

@jamesknelson PR welcome 👍

@EslamHiko
Copy link
Member

hello I want to work on this feature
as I understand
this option will disable serveIndex
in server.js

contentBaseIndex: () => {
        if (Array.isArray(contentBase)) {
          contentBase.forEach((item) => {
              app.get('*', serveIndex(item));
          });
        } else if (
          !/^(https?:)?\/\//.test(contentBase) &&
          typeof contentBase !== 'number'
        ) {
            app.get('*', serveIndex(contentBase));
        }
      }

the new code will be

contentBaseIndex: () => {
   if(options.devServer.serveIndex){
        if (Array.isArray(contentBase)) {
          contentBase.forEach((item) => {
              app.get('*', serveIndex(item));
          });
        } else if (
          !/^(https?:)?\/\//.test(contentBase) &&
          typeof contentBase !== 'number'
        ) {
            app.get('*', serveIndex(contentBase));
        }
     }
   }

instead of directory listing the files in folders without index.html it'll show the message Cannot GET /folder/

so am I getting it right?
and one more thing I don't know how to add a new option? please, can you tell me how would I add the new option?

excuse me I'm new to WebPack.

@alexander-akait
Copy link
Member

Look on other options and just send a PR

@EslamHiko
Copy link
Member

@evilebottnawi I added the new option and I tested it on one of the examples in the examples/api/simple folder
if you set the option in simple/webpack.config.js serveIndex to true it'll directory list the files simple.txt in the route /folder else it'll show the message Cannot GET /folder/
so did I do it right?
if there is anything wrong or I misunderstood something please tell me and I will do my best to fix it.
I will really appreciate any advice or feedback.

@alexander-akait
Copy link
Member

@EslamHiko we don't add this feature https://github.com/webpack/webpack-dev-server/blob/master/lib/Server.js#L555 if serveIndex: false (by default it is true)

@alexander-akait
Copy link
Member

Fixed #1752

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

No branches or pull requests

3 participants