Last active
March 19, 2018 05:31
-
-
Save dohoons/e5ac3ac2851410341430ca8af8c5486b to your computer and use it in GitHub Desktop.
gulp-webserver : middleware for support post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'), | |
fs = require('fs'), | |
path = require('path'), | |
webserver = require('gulp-webserver'); | |
gulp.task('server', function() { | |
var dist = './dist'; | |
return gulp.src(dist).pipe(webserver({ | |
host: '0.0.0.0', | |
port: 4000, | |
livereload: false, | |
directoryListing: { | |
enable: false, | |
path: dist | |
}, | |
middleware: [ | |
(req, res, next) => { | |
var filepath = path.join(path.resolve(__dirname), dist, req.url); | |
if ( | |
'POSTPUTDELETE'.indexOf(req.method.toUpperCase()) > -1 | |
&& fs.existsSync(filepath) | |
&& fs.statSync(filepath).isFile() | |
) { | |
res.end(fs.readFileSync(filepath)); | |
} | |
next(); | |
} | |
], | |
open: false | |
})); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment