Comments (4)
The check for something like Accept: text/html
is just one attempt at verifying that the current request is HTML and can/should be overwritten. It's a simple 'filter' that will exclude things like binary files, JS, CSS etc.
Are there any possibilities to inject the script for requests with not Accept: html header? In other words to disable this check?
You might want to take a look at resp-modifier instead. This module basically 'steals' all of the logic from this one with some added features (that I needed myself for Browsersync). For example, what you're really suggesting in your op is the idea of a whitelist - where the response is overwritten regardless.
var resp = require('resp-modifier');
var mw = resp({
rules: [
{
match: "some string",
replace: "some other string",
paths: ["**/*.html"] // whitelist all html files, skips all checks
}
]
});
app.use(mw)
from connect-livereload.
@shakyShane: thanks, I appreciate your help. I came up across this module as I was trying to migrate from all the complexity of Browsersync. But it seems that the logic is the same and the underlying concept also. If I got it right the resp-modifier
is just a middleware and does not do all the server/watch/reload magic, right?
Another thing: to see if the script can actually be injected, I would check the response delivered by the server to see if its actually HTML instead of reading the request headers. However, I might be missing something here.
And finally: I want to make use of this module in electron and due to a bug the request headers does not contain Accept
. My workaround was to use a middleware
and add Accept
to all *.html
requests, but I also had no success though (also not in case of Browsersync since user middlewares are run after resp-modifier
).
from connect-livereload.
yep, resp-modifier is just a simple middleware for modifying responses, it has no direct relationship to Browsersync
Another thing: to see if the script can actually be injected, I would check the response delivered by the server to see if its actually HTML instead of reading the request headers. However, I might be missing something here.
Yep, we do that too - the headers check is just 'first line of defense'
also not in case of Browsersync since user middlewares are run after resp-modifier)
You can force your middlewares to the 'top of the stack' in Browsersync quite easily
var browserSync = require('browser-sync').create();
browserSync.init({
server: './app'
}, function (err, bs) {
bs.addMiddleware("*", function (req, res, next) {
res.setHeader('accept', 'text/html');
next();
}, {override: true});
// override ensures your middleware always runs before any internals
});
from connect-livereload.
@shakyShane thanks for the quick Browsersync tutorial
I still think that checking the headers is little bit too restrictive, what about Accept: */*
? Or accepts with multiple values (e.g. the infamous image/webp,*/*;q=0.8
sent with all chrome requests). Nonetheless, I must confess that I have no better solution for now! I might as well close this issue (or should it leave it open as feature request?).
from connect-livereload.
Related Issues (20)
- <pre> trap for snippet HOT 1
- Reload snippet inject in wrong potision when no close <body>/<html> tag HOT 5
- Gulp recipe HOT 1
- the rules has a problem HOT 4
- Using connect-livereload in an Express node app HOT 1
- Documentation for 'disableCompression' option HOT 1
- Not working with superstatic HOT 1
- v0.5.4 not published on npm HOT 1
- The server is up but no live reloading HOT 1
- livereload does not work with Angular2 component styleUrls
- Livereload shadow dom web components HOT 1
- Please delete
- how about using it in koa2
- No injection when using Pug HOT 1
- TypeError: Cannot read property 'split' of undefined HOT 10
- How do you close the server programmatically? HOT 1
- livereload.js load error for proxy cases.
- help/maintainer wanted
- Not injecting when using EJS HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from connect-livereload.