gulp-webserver icon indicating copy to clipboard operation
gulp-webserver copied to clipboard

Cannot GET html & gulp.src location ignored.

Open Melonbwead opened this issue 10 years ago • 25 comments

This is my gulp webserver task:

gulp   = require "gulp"
$      = do require "gulp-load-plugins"
gulp.task "webserver", ->
  gulp.src "dist"
    .pipe $.webserver(
      directoryListing : true
      host             : "0.0.0.0"
      port             : 9000
    )

When i open up http://127.0.0.1:9000/ it ignores the the gulp.src location i've set and uses the root of the folder. But i can see files being listed: listing_directory__

If i click into a index.html for example inside the dist folder. i get this message on the page. Cannot GET /dist/index.html

Melonbwead avatar Aug 22 '14 12:08 Melonbwead

We have exactly the same problem! It's weird cause when I run only one task:

gulp webserver

The server works, but with multiple tasks is broken. 0.5.0 works like a charm.

hinok avatar Aug 22 '14 14:08 hinok

Also having this problem :(

robbiet480 avatar Aug 25 '14 21:08 robbiet480

Sorry guys this is related to this PR: https://github.com/schickling/gulp-webserver/pull/5

I try to fix it as soon as I get the chance. Please feel free to commit a PR on your own to solve this problem. :+1:

schickling avatar Aug 26 '14 07:08 schickling

I ran into this problem with gulp-connect which is how I found this project. The fact that I have the exact same problem with both makes me think the issue is with a setting on my computer.

I tried 0.5.0 based on Hinok's comment but no luck.

Definitely looking forward to solving this one.

MCTaylor17 avatar Aug 27 '14 08:08 MCTaylor17

@schickling I was trying to fix this issue and was wondering, how should this function when you pass an array of paths or glob to the gulp.src?

For example, if I have:

gulp.src(['dist', 'coverage']).pipe(webserver({...}));

davejlong avatar Sep 09 '14 20:09 davejlong

Just a note, by simply moving the line

if (config.directoryListing.enable) {
    app.use(serveIndex(path.resolve(config.directoryListing.path), config.directoryListing.options));
}

Inside the through.obj function argument and changing config.directoryListing.path to file.path, will make it so the directory listing sort of works. It only shows the first path for an array of files in gulp.src.

davejlong avatar Sep 09 '14 20:09 davejlong

related to #14. Just removing the directoryListing option fix the root for me.

MoOx avatar Nov 11 '14 07:11 MoOx

But this will only solve to serve content from the root, not if you specify a specific path

elmarkou avatar Nov 13 '14 12:11 elmarkou

+1

agross avatar Feb 23 '15 16:02 agross

Using gulp.src('./') solved my problem about getting files content.

cedeber avatar Mar 24 '15 09:03 cedeber

#5 solve this problem. Using this setting:

directoryListing: {
    enable:true,
    path: 'app'
}

animabear avatar Apr 04 '15 09:04 animabear

I ran into this issue working on my second or third gulp project on my machine. The last two projects I've started exhibit this issue, while the very first one still works. I've even tried copy pasting in the code and I still get the issue of the 404 and the src being the root of my projects. Changing ports doesn't make it work.

However, as @hinok mentioned, just running the webserver task standalone does work

thescientist13 avatar May 03 '15 17:05 thescientist13

I fixed this issue with the following gulp task.

gulp.task 'webserver', ->
  gulp.src 'public'
    .pipe webserver(
      fallback:   'index.html' # gulp-webserver needs this for html5
      livereload: true
      open:       true
      directoryListing:
        enable: true
        path:   'public'
      )

scottyantipa avatar Jun 05 '15 17:06 scottyantipa

My public and dist folder are siblings, so I am trying to serve the root directory, but I keep getting a CANNOT GET public/index.html error.

gulp.task('webserver', function() {
  gulp.src('root')
    .pipe(webserver({
        open: true,
        fallback:   'index.html',
        livereload: true,
        directoryListing: {
            enable: true,
            path: 'example'
        }
    }));
});

However, I can serve my public folder properly when my src is public, but I won't be able to reference my JavaScript in my dist folder. Any suggestions?

moneytree-doug avatar Jul 28 '15 02:07 moneytree-doug

Note to consider... when you set directoryListing: true renders only the root directory, regardless of the src path you specify in gulp.src('whateverPathYouChoose') so I had to specify an object to make it work properly and render my static files correctly.

something like this:

directoryListing: {
        enable: true,
        path: 'example'
},

You may want to include that in the readme, and provide a better explanation.

bialikover avatar Aug 02 '15 04:08 bialikover

As @cedriceberhardt mentioned, using gulp.src('./') works. Apparently, this points to root rather than gulp.src('root')

mii9000 avatar Aug 05 '15 12:08 mii9000

I have tried all of this solutions and none of them works for me. Whatever I do I get Cannot Get

TeodorKolev avatar Oct 18 '15 10:10 TeodorKolev

Any progress on this? gulp-webserver is useless without this working.

toymachiner62 avatar Jan 20 '16 16:01 toymachiner62

changing my settings from

directoryListing: true

to

directoryListing: {
  enable: true,
  path: 'app'
}

works for me

konekoya avatar Jan 27 '16 08:01 konekoya

> gulp.src('./app')
>     .pipe(server({
>         open: true,
>         fallback: 'index.html',
>         livereload: true,
>         directoryListing: {
>                 enable: true,
>                 path: './app'
> }

now this working for me except one problem - index.html doesn't open automaticly

scoutrul avatar Jan 30 '16 12:01 scoutrul

Removed directoryListing completely and it now opens index.html automatically.

gulp.src("build")
    .pipe(webserver({
        livereload: true,
        fallback: "index.html",
        port: 8080,
        open: true
    }));

itsmhuang avatar Aug 02 '16 23:08 itsmhuang

@frontools solution works :+1:

atais avatar Jan 31 '17 16:01 atais

This worked for me. Set open to the complete path rather than true

  	open: 'http://localhost:8000/index.html'

codemansam avatar Apr 06 '17 02:04 codemansam

@itsmhuang Thanks!!

rafaelblink avatar Apr 29 '17 00:04 rafaelblink

@itsmhuang Thanks!! http://localhost:8000/#!/home

JonyBlack avatar May 10 '17 15:05 JonyBlack