It would be nice to have the connect.directory middleware implemented if the base directory only contains subdirectories and not an index file.
My current setup is that my root directory contains subdirectories which contain the index file. So when browser sync opens up my browser, I get a Cannot GET / error. So I currently have to spin up my own connect server using the directory middleware which lists the directories being watched by browser sync and I click into the subdirectory I want. Hope that makes sense.
I adding a directory option to the options.server method. It can be set to true or it can be an object that has access to the index, hidden, and filter options the Connect directory middleware offers. Let me know what you think: https://github.com/jeremypeter/browser-sync/commit/97b4ff6f7ad0fe8d5d3ed002c3cae0ae624ad251
Hi, sorry I missed the first post.
This is good timing as I was just thinking we need this feature - so thanks :)
Your code needs a couple of small tweaks to better conform with the architecture of BrowserSync, I'll spend some time in the morning adding some notes to it & with a nudge in the right direction we'll get it into core.
Thanks for taking the time to contribute.
No problem, I figured it wouldn't take too much to get it into core.
I wanted this feature from the command-line too, so unfortunately it was a lot more work than it looks initially.
Thanks for the quick turnaround. I have a question. I noticed it lists the index.html instead of serving it up. Is this the desired solution? Or would be serving the index file if the folder contained it be the desired effect? I know by changing the order in which the addDirectory and addBaseDir methods are called would fix this, but I'd just wanted to know if the current setup up is the desired behavior. Thanks!
How would you get to the directory listing if it was the other way around?
Sent from my iPhone
On 26 Mar 2014, at 17:48, jeremypeter [email protected] wrote:
Thanks for the quick turnaround. I have a question. I noticed it lists the index.html instead of serving it up. Is this the desired solution? Or would be serving the index file if the folder contained it be the desired effect? I know by changing the order in which the addDirectory and addBaseDir methods are called would fix this, but I'd just wanted to know if the current setup up is the desired behavior. Thanks!
—
Reply to this email directly or view it on GitHub.
If you were to swap the order of the addDirectory and addBaseDir methods you would still get a directory listing. However, you wouldn't have to click the index.html file to view the page. You would just need to click the folder that contains it. So the url would look something like:
http:localhost:3002/directory-01/
The way it's set up now, you have to actually click on the index.html file so the url becomes:
http://localhost:3002/directory-01/index.html
Example:

I don't know, maybe it's me being too picky.
No don't be silly - I'm happy to discuss features and tweak them to suit peoples needs.
Sent from my iPhone
On 26 Mar 2014, at 22:16, jeremypeter [email protected] wrote:
If you were to swap the order of the addDirectory and addBaseDir methods you would still get a directory listing. However, you wouldn't have to click the index.html file to view the page. You would just need to click the folder that contains it. So the url would look something like:
http:localhost:3002/directory-01/The way it's set up now, you have to actually click on the index.html file so the url becomes:
http://localhost:3002/directory-01/index.htmlI don't know, maybe it's me being too picky.
—
Reply to this email directly or view it on GitHub.
I fail to understand how to make it work?
http://www.browsersync.io/docs/options/#option-server
server: {
baseDir: ['dist'],
directory: true
}

How can I make de server only display a listing if no index.html is found?
Yeah I wonder how to do it too: list the directory if no index.html is found, serve index.html if it exists. Which would sound like a normal behaviour.
why not do this? :
var listDirectory = true;
if (fs.existsSync('index.html')) {
listDirectory = false
}
var option = {
directory: listDirectory
};
That only works for one specific directory I think? Not when you have a mix where some directories have a index and some don't?
+1 for capturing apache-like DirectoryIndex behavior (e.g.; use index.html or whatnot if found, else show directory listing). Is there enough traction for this be a new feature request?
Haven't really dug into browserSync src yet... maybe a job for connect-modrewrite?
Ran into this issue when setting up my Angular 2 learning directories into multiple directories like app1, app2 etc. It would really be nice to have the feature if serving index.html from the subdirectories if found else show the directory listing when the directory option is set to true.
Hej, is it correct that it’s still not possible to enable directory listing and server index files (like index.html) if they exist?
Thanks, Michael
Hej, is it correct that it’s still not possible to enable directory listing and server index files (like index.html) if they exist?
After digging through the sources. Yes, it its. Since serve-index is used and it seems that one can’t accomplish that with passing options to serve-index
But isn’t it possible to check if the current directory has an index file and react to this over here?
Going to explore this … just in case: Would you accept a pull request for that?
Most helpful comment
I fail to understand how to make it work?
http://www.browsersync.io/docs/options/#option-server
How can I make de server only display a listing if no index.html is found?