mirror of
https://github.com/ivabus/urouter
synced 2024-11-24 17:35:11 +03:00
Ivan Bushchik
886c4cf2fa
- Use serde_json::from_reader in alias list initialization - Compile all regexes in initialization, not while recieving first triggering request - Count regex compilation time - Specify version in Server responce header Signed-off-by: Ivan Bushchik <ivabus@ivabus.dev>
1.9 KiB
1.9 KiB
urouter
Static (list of routes read once) http router for routing small domains.
Installation
cargo install urouter
Edit alias.json
(or any other JSON file, check --alias-file
option) and cargo run
alias.json
specification
JSON file with array of sets (or set with one field of arrays of sets with --alias-file-is-set-not-a-list
, may be useful i.e. Nix packaging).
Each set contains 2 necessary elements and 1 optional.
- Necessary
uri
(string) - of url after host (e.g.,/
,some/cool/path
, should not start with/
(only for root))alias
(set) - set of one fieldurl
(string) - redirect to url with HTTP 303 See Otherfile
(string) - read file from path--dir/file
where--dir
is option (default:.
, see--help
) and respond with HTTP 200 OK withcontent-type: text/plain
text
(string) - plain text HTTP 200 OK withcontent-type: text/plain
- Optional
agent
(set) - set of one necessary field and one optionalregex
(string) - regular expression to match user-agent HTTP headeronly_matching
(bool, optional, false by default) - if false whole alias will be visible for any user agent, if true only for regex matched
Set of array of sets
{
"alias": [
{
"uri": "/",
"alias": {
"url": "https://somecoolwebsite"
}
}
]
}
alias.json
example
[
{
"uri": "/",
"alias": {
"url": "https://somecoolwebsite"
}
},
{
"uri": "/",
"alias": {
"file": "somecoolscript"
},
"agent": {
"regex": "^curl/[0-9].[0-9].[0-9]$",
"only_matching": false
}
},
{
"uri": "text",
"alias": {
"text": "sometext"
}
}
]
Agent matching made for curl https://url | sh
like scripts.
License
The project is licensed under the terms of the MIT license.