http-multiserver
Version, currently 0.1.14 versions
- 0.2.0latestAug 16, 2018
- 0.1.2not indexedDec 13, 2019
- 0.1.1not indexedDec 13, 2019
- 0.1.0not indexedDec 13, 2019
github.com/vladfaust/http-multiserver.cr
Mount multiple web applications 🚦
24 stars
0 dependents
License: MIT
Nothing has been indexed for 0.1.1 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.
Installation
# Add this to your shard.yml
dependencies:
http-multiserver:
github: vladfaust/http-multiserver.cr
version: ~> 0.1.1Then run:
shards installshard.yml
No shard.yml has been indexed for 0.1.1. You can read it on the repository.
Dependencies
Unknown: the shard.yml for this version has not been read yet.
README
This README is the one indexed from the repository at its latest ref, not from the tag for this version.
# HTTP::Multiserver
[](https://crystal-lang.org/)
[](https://travis-ci.org/vladfaust/http-multiserver.cr)
[](https://vladfaust.com/http-multiserver.cr)
[](https://github.com/vladfaust/http-multiserver.cr/releases)
[](https://github.com/veelenga/awesome-crystal)
[](https://vladfaust.com)
Crystal requests dispatcher.
## About
`HTTP::Multiserver` dispatches a server request to another vanilla `HTTP::Server` depending on its path similar to Ruby's [Rack::URLMap](http://www.rubydoc.info/gems/rack/Rack/URLMap).
## Installation
Add this to your application's `shard.yml`:
```yaml
dependencies:
http-multiserver:
github: vladfaust/http-multiserver.cr
version: ~> 0.2.0
```
This shard follows [Semantic Versioning 2.0.0](https://semver.org/), so see [releases](https://github.com/vladfaust/http-multiserver.cr/releases) and change the `version` accordingly.
## Usage
### Basic example
```crystal
require "http-multiserver"
simple_server = HTTP::Server.new([HTTP::LogHandler.new]) do |context|
context.response.print("Hello from Simple Server!")
end
# For example purposes
resque = Resque::Server.new
multiserver = HTTP::Multiserver.new({
"/resque" => resque,
"/" => simple_server,
}, [HTTP::ErrorHandler.new(true)]) do |context|
# This is an optional custom fallback handler; by default returns "404 Not Found"
context.response.status_code = 418
context.response.print("☕ #{context.request.path} not found")
end
multiserver.bind_tcp(5000)
multiserver.listen
```
`HTTP::Multiserver` extends from a regular `HTTP::Server`, so it *CAN* have its own handlers. Same for underlying servers, they obviously *CAN* have their own handlers too.
### Mapping
Mapping relies on either `String` or `Regex` keys; when using `String` as a key, a slash is automatically appended to it.
Assuming that this map is passed to `HTTP::Multiserver` initializer:
```crystal
map = {
"/foo" => foo_server,
%r{/bar} => bar_server,
"/" => fallback_server
}
multiserver = HTTP::Multiserver.new(port, map)
```
This is how the request is dispatched under the hood (simplified):
```crystal
internal_map = {
%r{^/foo/} => foo_server,
%r{/bar} => bar_server,
%r{^/} => fallback_server
}
path = request.path.append_slash # "/foo/abc" turns into "foo/abc/"
server = internal_map.find { |regex, _| regex.match(path) }
server ? server.call(context) : not_found
```
Please see [specs](https://github.com/vladfaust/http-multiserver.cr/blob/master/spec/http-multiserver_spec.cr) for dispatching specifications.
## Performance
As mentioned above, `HTTP::Multiserver` is just a regular `HTTP::Server` which dispatches the handling to underlying servers based on super-fast `Regex.match`. A very tiny impact on the performance is expected if any.
## Contributing
1. Fork it ( https://github.com/vladfaust/http-multiserver.cr/fork )
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create a new Pull Request
## Contributors
- [@vladfaust](https://github.com/vladfaust) Vlad Faust - creator, maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.1.1- Tagged
- Dec 13, 2019
- Commit
b314199737c4- Indexed
- not yet
Dependents
No indexed shard depends on this one yet.
Repository
github.com/vladfaust/http-multiserver.cr
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 12, 2026
- Synced
- Aug 12, 2026
- Versions
- 4