blob: b204dc0bfcb696121f77bf16f8c6794343a8b9a9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
import cache
import database
import gleam/erlang/process
import mist
import request
import simplifile
import sqlight
import wisp
pub fn main() {
wisp.configure_logger()
let _ = simplifile.create_directory("./data")
let image_cache = cache.load_themes()
let index_html = case simplifile.read("index.html") {
Ok(content) -> content
Error(_) -> {
wisp.log_error("Failed to read index.html")
""
}
}
use connection <- sqlight.with_connection("./data/count.db")
database.setup(connection)
let secret_key_base = wisp.random_string(64)
let assert Ok(_) =
wisp.mist_handler(
fn(request) {
request.handle(request, connection, image_cache, index_html)
},
secret_key_base,
)
|> mist.new
|> mist.port(3000)
|> mist.start_http
process.sleep_forever()
}
|