馃 A practical web framework for Gleam
at main 34 lines 887 B view raw
1import app/router 2import app/web 3import gleam/erlang/process 4import mist 5import tiny_database 6import wisp 7import wisp/wisp_mist 8 9pub const data_directory = "tmp/data" 10 11pub fn main() { 12 wisp.configure_logger() 13 let secret_key_base = wisp.random_string(64) 14 15 // A database creation is created here, when the program starts. 16 // This connection is used by all requests. 17 use db <- tiny_database.with_connection(data_directory) 18 19 // A context is constructed to hold the database connection. 20 let context = web.Context(db: db) 21 22 // The handle_request function is partially applied with the context to make 23 // the request handler function that only takes a request. 24 let handler = router.handle_request(_, context) 25 26 let assert Ok(_) = 27 handler 28 |> wisp_mist.handler(secret_key_base) 29 |> mist.new 30 |> mist.port(8000) 31 |> mist.start_http 32 33 process.sleep_forever() 34}