mirror of
https://github.com/SinTan1729/chhoto-url
synced 2025-04-19 11:20:00 -05:00
Compare commits
No commits in common. "16bc211f9fcb4c4008d40fc897dd1fb771be2b2d" and "5183279cab799f410f5e4f10c6bfad0cf3c4b417" have entirely different histories.
16bc211f9f
...
5183279cab
5 changed files with 7 additions and 20 deletions
1
Makefile
1
Makefile
|
@ -24,7 +24,6 @@ docker-test: docker-local docker-stop
|
|||
docker run -p ${PORT}:${PORT} --name chhoto-url -e password="${PASSWORD}" -e public_mode="${PUBLIC_MODE}" \
|
||||
-e site_url="${SITE_URL}" -e db_url="${DB_URL}" -e redirect_method="${REDIRECT_METHOD}" -e port="${PORT}"\
|
||||
-e slug_style="${SLUG_STYLE}" -e slug_length="${SLUG_LENGTH}" -e cache_control_header="${CACHE_CONTROL_HEADER}"\
|
||||
-e api_key="${API_KEY}"\
|
||||
-d chhoto-url
|
||||
docker logs chhoto-url -f
|
||||
|
||||
|
|
|
@ -193,13 +193,10 @@ The server will send a confirmation.
|
|||
In order to use API key validation, set the `api_key` environment variable. If this is not set, the API will default to cookie
|
||||
validation (see section above). If the API key is insecure, a warning will be outputted along with a generated API key which may be used.
|
||||
|
||||
Example Linux command for generating a secure API key: `tr -dc A-Za-z0-9 </dev/urandom | head -c 128`
|
||||
|
||||
To add a link:
|
||||
``` bash
|
||||
curl -X POST -H "X-API-Key: <YOUR_API_KEY>" -d '{"shortlink":"<shortlink>", "longlink":"<longlink>"}' http://localhost:4567/api/new
|
||||
```
|
||||
Send an empty `<shortlink>` if you want it to be auto-generated. The server will reply with the generated shortlink.
|
||||
|
||||
To get a list of all the currently available links:
|
||||
``` bash
|
||||
|
|
|
@ -43,16 +43,15 @@ async fn main() -> Result<()> {
|
|||
if let Ok(key) = env::var("api_key") {
|
||||
if !auth::is_key_secure() {
|
||||
eprintln!("API key is insecure! Please change it. Current key is: {}. Generated secure key which you may use: {}", key, auth::gen_key())
|
||||
} else {
|
||||
eprintln!("Secure API key was provided.")
|
||||
}
|
||||
}
|
||||
|
||||
// Tell the user that the server has started, and where it is listening to, rather than simply outputting nothing
|
||||
eprintln!("Server has started at 0.0.0.0 on port {port}.");
|
||||
if let Some(site_url) = env::var("site_url").ok().filter(|s| !s.trim().is_empty()) {
|
||||
eprintln!("Configured Site URL is: {site_url}.");
|
||||
}
|
||||
eprintln!(
|
||||
"Server has started at 0.0.0.0 on port {}. Configured Site URL is: {}",
|
||||
port,
|
||||
env::var("site_url").unwrap_or(String::from("http://localhost"))
|
||||
);
|
||||
|
||||
// Actually start the server
|
||||
HttpServer::new(move || {
|
||||
|
|
|
@ -61,10 +61,7 @@ pub async fn add_link(
|
|||
.expect("Supplied port is not an integer");
|
||||
let url = format!(
|
||||
"{}:{}",
|
||||
env::var("site_url")
|
||||
.ok()
|
||||
.filter(|s| !s.trim().is_empty())
|
||||
.unwrap_or(String::from("http://localhost")),
|
||||
env::var("site_url").unwrap_or(String::from("http://localhost")),
|
||||
port
|
||||
);
|
||||
let response = CreatedURL {
|
||||
|
|
|
@ -62,12 +62,7 @@ pub fn is_api_ok(http: HttpRequest) -> Response {
|
|||
} else {
|
||||
// If the API key isn't set, but an API Key header is provided
|
||||
if auth::api_header(&http).is_some() {
|
||||
Response {
|
||||
success: false,
|
||||
error: true,
|
||||
reason: "An API key was provided, but the 'api_key' environment variable is not configured in the Chhoto URL instance".to_string(),
|
||||
pass: false
|
||||
}
|
||||
Response {success: false, error: true, reason: "An API key was provided, but the 'api_key' environment variable is not configured in the Chhoto URL instance".to_string(), pass: false}
|
||||
} else {
|
||||
Response {
|
||||
success: false,
|
||||
|
|
Loading…
Reference in a new issue