denisdefreyne / adsf Goto Github PK
View Code? Open in Web Editor NEWWeb server that you can launch instantly in any directory
License: MIT License
Web server that you can launch instantly in any directory
License: MIT License
How out of scope would it be to consider adding basic auth support?
Ideally - I would love adsf to automatically detect if there is an ADSF_AUTH
environment variable, and act accordingly, so we can run:
$ ADSF_AUTH=admin:p4ssw0rd adsf
Since this is Rack, I am guessing it should not be too difficult to add, like:
if ENV['ADSF_AUTH']
user, pass = ENV['ADSF_AUTH'].split ':'
use Rack::Auth::Basic, "Protected Area" do |username, password|
username == user && password == pass
end
end
ads
returns a Content-Type
response header, but its missing the charset=utf-8
component. HTML documents with a <meta charset="utf-8">
declaration works anyway, but other text resources like text/plain
doesn’t have a reliable fallback mechanism like this (the BOM character causes more problems than it solves). text/css
has @charset="utf-8";
but when did you last see that in use?
On Windows (sorry) paths will not start with /
but with e.g. C:/
. Perhaps it's better to compare the output of File.absolute_path(root_dir)
with root_dir
and throw if they differ?
The adsf-live gem relies on Rack::LiveReload, which by default still loads swfobject.js as a fall back for browsers that do not support web sockets. This is unlikely to be of use to anyone anymore in 2022, Flash has been deprecated long ago.
While it would be better if the rack -livereload gem changed it's behaviour I don't think they will; the repo sees very few updates and does not accept issue reports. However, we could simply fix it from here by adding the parameter no_swf: true
on the call to Rack::LiveReload (in lib/adsf/server.rb:66
)
A Dead Simple server should probably be as much compatible as possible.
Adsf version 1.4.7 started using lower case headers to support rack 3, however the rack-livereload gem that adsf-live depends on has not yet been updated and expects upper case headers. I realise this is something that needs to be updated in the rack-livereload gem, but that project seems dormant.
Until that gem gets updated, I created this monkey patch that seems to work:
module Rack
class LiveReload
class ProcessingSkipAnalyzer
def html?;@headers['content-type'] =~ %r{text/html}; end
end
def call(env)
result = dup._call(env)
if (headers=result[1]).is_a?(Hash) && headers['Content-Length']
headers['content-length']=headers.delete('Content-Length')
headers.transform_keys!{_1.downcase}
end
result
end
end
end
It's a bit tricky to get the patch to load at the right time when used with nanoc, I ended up creating a custom nanoc command.
Hey,
Have you thought of initializing Rack::LiveReload
with any unused port rather than its default? Having all instances use the same port prevents running two [Nanoc] sites with nanoc live
in parallel.
When uploading a static site to most static site hosts, they allow accessing any HTML page, without the HTML extension - so for example, server.com/software
will load the software.html
file if it is found.
It would be very helpful if such a behavior is either enabled by default in adsf, or can be added with a command line flag.
Based on this SO answer I have prepared the following config.ru
file as a proof of concept:
# config.ru - run with rackup
require 'adsf'
class OptionalHtml
def initialize(app)
@app = app
end
def call(env)
orig_path = env['PATH_INFO']
resp = @app.call(env.merge!({'PATH_INFO' => "#{orig_path}.html"}))
found = resp[0] == 404 ? false : resp
found or @app.call(env.merge!('PATH_INFO' => orig_path))
end
end
use OptionalHtml
use Adsf::Rack::IndexFileFinder, root: '.'
run Rack::File.new '.'
Would it make sense to add such a behavior to adsf?
Hello!
list folders if index.html not present support
Shift-Clicking the browser’s Reload button to force-reload and bypass the cache shouldn’t be necessary on a development server.
When I installed your gem from rubygems.org and tried to run it, it crashed:
/Users/angelika/.rvm/gems/ruby-2.3.0/gems/adsf-1.2.0/bin/adsf:64:in `<top (required)>': uninitialized constant Rack::Handler::Mongrel (NameError)
from /Users/angelika/.rvm/gems/ruby-2.3.0/bin/adsf:23:in `load'
from /Users/angelika/.rvm/gems/ruby-2.3.0/bin/adsf:23:in `<main>'
from /Users/angelika/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
from /Users/angelika/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'
I had to clone the repo and build the gem myself, it's working now. I know it's not a big deal, but maybe you could publish the current version (without Mongrel dependency) to rubygems.org, so it's more convenient for people to install it.
Hey. Thanks for your great job. I just wondered if it was possible to add a custom header ?
To prevent such exceptions like
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
Thanks
adsf-live should send the path of the web page to live reload.
adsf-live sends the path to the file here
path: "#{Dir.pwd}#{path}"
instead of path: path
You typically only want to reload the page if the change occurred on the page you are viewing. When you change a layout in nanoc it will send many changed pages over the web socket. For livereload to know if the current page changed it needs to compare document.location.pathname
with path
. At this time it always reloads even if no match is found, but that results in ugly flickering if many pages change. It's not hard to modify the livereload.js to only reload if the path matches, but this comparison is needlessly complicated because the file path is being sent, from which the path first needs to be extracted.
No warnings
It shows /Users/jmfaber/.rvm/gems/ruby-3.1.2/gems/rack-3.0.7/lib/rack/file.rb:5: warning: Rack::File is deprecated and will be removed in Rack 3.1
Rack::File
has been renamed to Rack::Files
apparently. Because adsf can no longer run on rack 2 (because it depends on the rackup gem that require rack 3), it should be safe to simply rename it here:
Line 69 in fd2aa50
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.