Skip to content

Commit

Permalink
chore: cleanup (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
o-az authored Nov 10, 2024
2 parents f5271b0 + 20146c6 commit 5bb4411
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 26 deletions.
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

# for development only
# this is the default location when you run d1 with `--local`
env.D1_DATABASE_FILEPATH =
env.D1_DATABASE_FILEPATH = # TODO: there has to be a simpler and better way to do this
let
dbDir = ".wrangler/state/v3/d1/miniflare-D1DatabaseObject";
in
Expand Down
24 changes: 2 additions & 22 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
use serde::{Deserialize, Serialize};
use serde_json::Value;
use url::Url;
use worker::*;

#[derive(Debug, Deserialize, Serialize)]
struct GenericResponse {
status: u16,
message: String,
}
mod utils;
use utils::*;

const DEV_ROUTES: [&str; 2] = ["/list", "/env"];

pub fn get_secret(name: &str, env: &Env) -> Option<String> {
match env.secret(name) {
Ok(value) => Some(value.to_string()),
Err(_) => None,
}
}

pub fn get_var(name: &str, env: &Env) -> Option<String> {
match env.var(name) {
Ok(value) => Some(value.to_string()),
Err(_) => None,
}
}

#[event(fetch)]
async fn fetch(request: Request, env: Env, _context: Context) -> Result<Response> {
let environment = get_var("ENVIRONMENT", &env).unwrap_or_default();
Expand All @@ -43,8 +25,6 @@ async fn fetch(request: Request, env: Env, _context: Context) -> Result<Response
return router.run(request, env).await;
}

console_log!("{}", url.query().unwrap_or_default());

let url_key = url.query().and_then(|q| q.split("key=").nth(1));
if url_key.is_none() {
return router.run(request, env).await;
Expand Down
15 changes: 15 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use worker::*;

pub fn get_secret(name: &str, env: &Env) -> Option<String> {
match env.secret(name) {
Ok(value) => Some(value.to_string()),
Err(_) => None,
}
}

pub fn get_var(name: &str, env: &Env) -> Option<String> {
match env.var(name) {
Ok(value) => Some(value.to_string()),
Err(_) => None,
}
}
3 changes: 0 additions & 3 deletions tasks.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
echo-env.exec = ''
echo $D1_DATABASE_FILEPATH
'';
wrangler.exec = ''
bunx wrangler@latest --config='wrangler.toml' "$@"
'';
Expand Down

0 comments on commit 5bb4411

Please sign in to comment.