Crates.io | urouter |
lib.rs | urouter |
version | 0.7.1 |
source | src |
created_at | 2023-12-18 11:14:16.113956 |
updated_at | 2024-09-25 18:31:04.895865 |
description | Small HTTP router |
homepage | |
repository | https://github.com/ivabus/urouter |
max_upload_size | |
id | 1073281 |
size | 65,130 |
Static (list of routes read once) http router for routing small domains.
cargo install urouter
Edit alias.json
(or any other JSON file, check --alias-file
option) and cargo run
alias.json
specificationJSON 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.
uri
(string) - of URL after host (e.g., /
, some/cool/path
, should not start with /
(only for root))alias
(set) - set of one field
url
(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 with content-type: text/plain
text
(string) - plain text with HTTP 200 OK with content-type: text/plain
html
(string) - plain text with HTTP 200 OK with content-type: text/html
external
(set) - download (every time) file using ureq
HTTP library and response with contents of downloaded resource with HTTP 200 OK and extracted content-type
from response
url
(string) - URL to downloadheaders
(set, optional) - headers to include with requestagent
(set, optional) - set of one necessary field and one optional
regex
(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{
"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"
}
},
{
"uri": "external",
"alias": {
"external": {
"url": "https://somecool.external.link",
"headers": {
"user-agent": "curl/8.6.0"
}
}
}
}
]
Agent matching made for curl https://url | sh
like scripts.
alias.json
location--alias_file
, will look up to this path, if file doesn't exist (or no access to it) will panic/etc/urouter/alias.json
XDG_CONFIG_HOME
is set, file would be $XDG_CONFIG_HOME/urouter/alias.json
$HOME
is set, file would be $HOME/.config/urouter/alias.json
The project is licensed under the terms of the MIT license.