@giovanny.lueilwitz
You can use the gulp-connect-redirect middleware to redirect http requests to https. Here's how you can set it up in your Gulpfile:
- Install the gulp-connect-redirect package:
1
|
npm install gulp-connect-redirect --save-dev
|
- Require the gulp and gulp-connect modules in your Gulpfile:
1
2
3
|
const gulp = require('gulp');
const connect = require('gulp-connect');
const redirect = require('gulp-connect-redirect');
|
- Add a task to redirect http requests to https:
1
2
3
4
5
6
7
8
9
|
gulp.task('redirect-http', function() {
return gulp.src('')
.pipe(redirect(function() {
return {
redirect: 'https://localhost:8080'
};
}))
.pipe(gulp.dest(''));
});
|
- Add the redirect task to your server task:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
gulp.task('server', function() {
connect.server({
root: 'app',
port: 8080,
https: true,
middleware: function(connect, opt) {
return [
redirect({
from: '^http://',
to: 'https://'
})
];
}
});
});
|
Now when you run the gulp server task, http requests will be automatically redirected to https.