gulp-serve-extended
v1.0.0
Published
Extending features on gulp-serve by Gusakov Nikita
Downloads
2
Maintainers
Readme
Extending features on gulp-serve by Gusakov Nikita...
postware
var gulp = require('gulp');
var serve = require('gulp-serve');
var fs = require('fs');
gulp.task('serve', serve('public'));
gulp.task('serve-build', serve(['public', 'build']));
gulp.task('serve-prod', serve({
root: ['public', 'build'],
port: 80,
hostname: 'localhost',
middleware: function(req, res) {
// custom optional middleware
},
postwares: [errorHandler]
}));
errorHandler = function(req, res, next) {
fs.readFile("404.html", function(err, data) {
//....
})
}
Original readme :>>
gulp-serve
Provide connect-server functionality, using connect.static
Install
Install with npm
npm i --save-dev gulp-serve
Usage
var gulp = require('gulp');
var serve = require('gulp-serve');
gulp.task('serve', serve('public'));
gulp.task('serve-build', serve(['public', 'build']));
gulp.task('serve-prod', serve({
root: ['public', 'build'],
port: 80,
hostname: 'localhost',
middleware: function(req, res) {
// custom optional middleware
}
}));
With HTTPS enabled (using built-in key and certificate for localhost
):
var gulp = require('gulp');
var serve = require('gulp-serve');
gulp.task('serve', serve('public'));
gulp.task('serve-build', serve(['public', 'build']));
gulp.task('serve-prod', serve({
root: ['public', 'build'],
port: 443,
https: true,
middleware: function(req, res) {
// custom optional middleware
}
}));
With HTTPS enabled (using self provided key and certificate):
var gulp = require('gulp');
var serve = require('gulp-serve');
gulp.task('serve', serve('public'));
gulp.task('serve-build', serve(['public', 'build']));
gulp.task('serve-prod', serve({
root: ['public', 'build'],
port: 443,
https: {
key: 'path/to/cert.key',
cert: 'path/to/cert.pem'
},
middleware: function(req, res) {
// custom optional middleware
}
}));