diff --git a/src/app/router.gleam b/src/app/router.gleam index 95910b5..cdacbe7 100644 --- a/src/app/router.gleam +++ b/src/app/router.gleam @@ -6,7 +6,7 @@ import app/web/root import wisp.{type Request, type Response} pub fn handle_request(req: Request, ctx: Context) -> Response { - use req: Request <- web.middleware(req) + use req <- web.middleware(req) case wisp.path_segments(req) { ["f", ..] -> file.handle_request(req, ctx) diff --git a/src/dumptruck.gleam b/src/dumptruck.gleam index 241af02..3748394 100644 --- a/src/dumptruck.gleam +++ b/src/dumptruck.gleam @@ -1,5 +1,7 @@ import app/config.{type Context, Context} import app/router +import app/web/file +import app/web/link import gleam/erlang/process import gleam/option.{Some} import gleam/pgo @@ -8,8 +10,13 @@ import mist import wisp fn with_context(continue: fn(Context) -> Nil) -> Nil { + wisp.log_info("Reading configuration from environment...") let config = config.load_config_from_env() + + wisp.log_info("Starting CUID Generator...") let assert Ok(cuid) = cuid.start() + + wisp.log_info("Connecting to Postgres...") let db = pgo.connect( pgo.Config( @@ -25,16 +32,27 @@ fn with_context(continue: fn(Context) -> Nil) -> Nil { ) let ctx = Context(db: db, config: config, cuid: cuid) + wisp.log_info("Initializing database...") + initialize_db(ctx) + continue(ctx) ctx.db |> pgo.disconnect } -pub fn main() { - use ctx <- with_context() +fn initialize_db(ctx: Context) -> Nil { + let assert Ok(_) = file.prepare_database(ctx) + let assert Ok(_) = link.prepare_database(ctx) + Nil +} +pub fn main() { wisp.configure_logger() + wisp.log_info("Welcome to Dumptruck!") + + use ctx <- with_context() + let assert Ok(_) = router.handle_request(_, ctx) |> wisp.mist_handler(ctx.config.secret_key_base) @@ -42,5 +60,7 @@ pub fn main() { |> mist.port(ctx.config.port) |> mist.start_http + wisp.log_info("Accepting requests!") + process.sleep_forever() } diff --git a/test/docker-compose.yml b/test/docker-compose.yml index 97392f7..855c86e 100644 --- a/test/docker-compose.yml +++ b/test/docker-compose.yml @@ -8,20 +8,20 @@ services: ports: - "5432:5432" - frontend: - image: dpage/pgadmin4 - environment: - PGADMIN_DEFAULT_EMAIL: "test@example.com" - PGADMIN_DEFAULT_PASSWORD: "test" - PGADMIN_LISTEN_PORT: "80" - PGADMIN_CONFIG_SERVER_MODE: "False" - PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED: "False" - depends_on: - - "db" - volumes: - - read_only: true - source: "servers.json" - target: "/pgadmin4/servers.json" - type: bind - ports: - - "8080:80" + # frontend: + # image: dpage/pgadmin4 + # environment: + # PGADMIN_DEFAULT_EMAIL: "test@example.com" + # PGADMIN_DEFAULT_PASSWORD: "test" + # PGADMIN_LISTEN_PORT: "80" + # PGADMIN_CONFIG_SERVER_MODE: "False" + # PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED: "False" + # depends_on: + # - "db" + # volumes: + # - read_only: true + # source: "servers.json" + # target: "/pgadmin4/servers.json" + # type: bind + # ports: + # - "8080:80"