gulp-webserver
gulp-webserver copied to clipboard
Headers not added with configured middleware?
Hello! I am using gulp-webserver
's middleware
option to set a header (Access-Control-Allow-Origin
). I have also configured livereload
. When I load my livereload.js
script, however, that header is not served.
Simplified version of my code:
const livereload = {
enable: true,
port: 18000,
filter: function (filename) {
// ...
}
};
gulp.src('.')
.pipe(webserver({
livereload,
directoryListing: true,
https: false,
middleware: [
(req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*'); // eg.
next();
}
]
}));
Example response headers:
HTTP/1.1 200 OK
content-type: application/json
date: Tue, 01 Aug 2017 19:37:26 GMT
connection: close
transfer-encoding: chunked
Having the same issue, where I want JSON files to have a json header and continue to next()
but yeah the header is coming out as text/html
. I worked around this by manually reading the json file from disk and res.end(content)
just after adding the header. Definitely would prefer not to have to do this though.