···4141 let db = Sqlite3.db_open db_path in
4242 try
4343 let rc = Sqlite3.exec db sql in
4444- let _ = Sqlite3.db_close db in
4444+ let _ = try Sqlite3.db_close db with _ -> true in
4545 match rc with
4646 | Sqlite3.Rc.OK ->
4747 Lwt.return_ok ()
···4949 let err_msg = Sqlite3.errmsg db in
5050 Lwt.return_error (Failure ("sql error: " ^ err_msg))
5151 with e ->
5252- let _ = Sqlite3.db_close db in
5252+ let _ = try Sqlite3.db_close db with _ -> true in
5353 Lwt.return_error e
54545555let parse_migration_filename filename =
+57
pegasus/lib/rsc.ml
···11+let debug = Sys.getenv_opt "DEMO_ENV" == Some "development"
22+33+let is_react_component_header str =
44+ String.equal str "application/react.component"
55+66+let stream_model ~location app =
77+ Dream.stream
88+ ~headers:
99+ [ ("Content-Type", "application/react.component")
1010+ ; ("X-Content-Type-Options", "nosniff")
1111+ ; ("X-Location", location) ]
1212+ (fun stream ->
1313+ [%lwt
1414+ let () =
1515+ ReactServerDOM.render_model ~debug
1616+ ~subscribe:(fun chunk ->
1717+ if debug then (Dream.log "Chunk" ; Dream.log "%s" chunk) ;
1818+ [%lwt
1919+ let () = Dream.write stream chunk in
2020+ Dream.flush stream] )
2121+ app
2222+ in
2323+ Dream.flush stream] )
2424+2525+let stream_html ?(skipRoot = false) ?bootstrapScriptContent
2626+ ?(bootstrapScripts = []) ?(bootstrapModules = []) app =
2727+ Dream.stream
2828+ ~headers:[("Content-Type", "text/html")]
2929+ (fun stream ->
3030+ [%lwt
3131+ let html, subscribe =
3232+ ReactServerDOM.render_html ~skipRoot ?bootstrapScriptContent
3333+ ~bootstrapScripts ~bootstrapModules ~debug app
3434+ in
3535+ [%lwt
3636+ let () = Dream.write stream html in
3737+ [%lwt
3838+ let () = Dream.flush stream in
3939+ [%lwt
4040+ let () =
4141+ subscribe (fun chunk ->
4242+ if debug then (Dream.log "Chunk" ; Dream.log "%s" chunk) ;
4343+ [%lwt
4444+ let () = Dream.write stream chunk in
4545+ Dream.flush stream] )
4646+ in
4747+ Dream.flush stream]]]] )
4848+4949+let createFromRequest ?(disableSSR = false) ?(layout = fun children -> children)
5050+ ?(bootstrapModules = []) ?(bootstrapScripts = [])
5151+ ?(bootstrapScriptContent = "") element request =
5252+ match Dream.header request "accept" with
5353+ | Some accept when is_react_component_header accept ->
5454+ stream_model ~location:(Dream.target request) (React.Model.Element element)
5555+ | _ ->
5656+ stream_html ~skipRoot:disableSSR ~bootstrapScriptContent ~bootstrapScripts
5757+ ~bootstrapModules (layout element)