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

example of dropping `.html` exention?

Open tomByrer opened this issue 8 years ago • 1 comments

Could someone provide an example of routing static webpages without their .html extension please? I looked at this thread, but I don't quite get it.

tomByrer avatar Feb 19 '16 01:02 tomByrer

Hello @tomByrer, not sure if you still need help with this and I can't say that i've got the prettiest solution for it.

webserver({
  middleware: function (req, res, next) {
    // Stuff to be ignored
    if (req.url.indexOf('assets') >= 0) {
      next();
      return
    }

    // If `/` is requested. append index to it
    if (req.url === '/') {
      req.url = '/index';
    }
    const url = req.url + '.html';
    req.url = url;
    next();
  }
})

viktorgardart avatar Aug 15 '16 10:08 viktorgardart