Skip to content

Commit

Permalink
Merge pull request #55 from JuliaWeb/s/asset-registry
Browse files Browse the repository at this point in the history
AssetRegistry
  • Loading branch information
Shashi Gowda authored Jun 13, 2018
2 parents c83c057 + fdb0dea commit 0ab1f0c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ os:
- linux
- osx
julia:
- 0.4
- 0.5
- 0.6
- nightly
matrix:
allow_failures:
- julia: nightly
notifications:
email: false
git:
Expand Down
3 changes: 2 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
julia 0.4
julia 0.6
Lazy
Hiccup
HttpCommon
HttpServer
URIParser
AssetRegistry
WebSockets
Compat 0.7.9
2 changes: 1 addition & 1 deletion src/Mux.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ include("websockets_integration.jl")
include("examples/basic.jl")
include("examples/files.jl")

defaults = stack(todict, basiccatch, splitquery, toresponse, pkgfiles)
defaults = stack(todict, basiccatch, splitquery, toresponse, assetserver, pkgfiles)
wdefaults = stack(todict, wcatch, splitquery)

end
18 changes: 17 additions & 1 deletion src/examples/files.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,23 @@ const ASSETS_DIR = "assets"
function packagefiles(dirs=true)
absdir(req) = Pkg.dir(req[:params][:pkg], ASSETS_DIR)
branch(req -> validpath(absdir(req), joinpath(req[:path]...), dirs=dirs),
req -> fresp(joinpath(absdir(req), req[:path]...)))
req -> (Base.warn_once("""
Relying on /pkg/ is now deprecated. Please use the package
`AssetRegistry.jl` instead to register assets directory
""");
fresp(joinpath(absdir(req), req[:path]...))))
end

const pkgfiles = route("pkg/:pkg", packagefiles(), Mux.notfound())


using AssetRegistry

function assetserve(dirs=true)
absdir(req) = AssetRegistry.registry["/assetserver/" * req[:params][:key]]
branch(req -> (isfile(absdir(req)) && isempty(req[:path])) ||
validpath(absdir(req), joinpath(req[:path]...), dirs=dirs),
req -> fresp(joinpath(absdir(req), req[:path]...)))
end

const assetserver = route("assetserver/:key", assetserve(), Mux.notfound())

0 comments on commit 0ab1f0c

Please sign in to comment.