commit 8bbcf54a438e3148ce7c5f1f45c32fd079d2f1df
parent ab168974869e5466427d1035e5bc82b78d97d28c
Author: Silas Brack <silasbrack@gmail.com>
Date: Sun, 20 Oct 2024 14:49:32 +0200
Adding more stuff to gleam
Diffstat:
3 files changed, 29 insertions(+), 11 deletions(-)
diff --git a/apps/my_app/flake.nix b/apps/my_app/flake.nix
@@ -31,6 +31,10 @@
src = ./.;
erlangPackage = pkgs.erlang_27;
};
+ # apps.default = {
+ # type = "app";
+ # program = "${}/bin/my";
+ # };
devShells.system.default = {
buildInputs = [
pkgs.gleam
@@ -40,6 +44,13 @@
pkgs.nodejs_22
];
};
+ # nixosConfigurations.vm = nixpkgs.lib.nixosSystem {
+ # system = system;
+ # modules = [
+ # (import ./vm.nix ( { pkgs = import nixpkgs {}; lib = nixpkgs.lib; my_app = pkgs.my_app; } ))
+ # nixos-shell.nixosModules.nixos-shell
+ # ];
+ # };
}
))
// {
diff --git a/apps/my_app/src/my_app/router.gleam b/apps/my_app/src/my_app/router.gleam
@@ -2,18 +2,25 @@ import gleam/string_builder
import my_app/web
import wisp.{type Request, type Response}
-/// The HTTP request handler- your application!
-///
pub fn handle_request(req: Request) -> Response {
- // Apply the middleware stack for this request/response.
- use _req <- web.middleware(req)
+ use req <- web.middleware(req)
+ let segments = wisp.path_segments(req)
+ case segments {
+ [] -> {
+ asdf(req)
+ }
+ ["api", ..] -> api_routes(req, segments)
+ _ -> wisp.not_found()
+ }
+}
- // Later we'll use templates, but for now a string will do.
+fn asdf(_req: Request) {
let body = string_builder.from_string("<h1>Hello, Silas!</h1>")
-
- // Return a 200 OK response with the body and a HTML content type.
wisp.html_response(body, 200)
- // wisp.response(200)
- // |> wisp.set_header("Content-Type", "text/html")
- // |> wisp.html_body(body)
+}
+
+fn api_routes(req: Request, segments: List(String)) {
+ case segments {
+
+ }
}
diff --git a/flake.lock b/flake.lock
@@ -27,7 +27,7 @@
},
"locked": {
"lastModified": 1,
- "narHash": "sha256-ieGRo5r3GhRDNpL4bfH7XImvfvNpxWceSmw5wvBoAkQ=",
+ "narHash": "sha256-W0xI3AT7bo+wLWqKBVbG+RwJgxsgZVjsylK16zntZr8=",
"path": "./apps/my_app",
"type": "path"
},