aboutsummaryrefslogtreecommitdiff
path: root/src/http_ffi.erl
diff options
context:
space:
mode:
authorHayleigh Thompson <me@hayleigh.dev>2024-01-05 08:25:08 +0000
committerGitHub <noreply@github.com>2024-01-05 08:25:08 +0000
commit775bc596ac84f5b28b4e0e1654525a360002711f (patch)
treed589203f67f2934fa4616d3c76d1e4cb523cdb16 /src/http_ffi.erl
parentc6b89cae8fcef56b6420698f311a8955919037c6 (diff)
downloadlustre-775bc596ac84f5b28b4e0e1654525a360002711f.tar.gz
lustre-775bc596ac84f5b28b4e0e1654525a360002711f.zip
🔀 Add flags for configuring the server's host and port. (#33)
* :sparkles: Add the option to include lustre_ui styles from a CDN. * :heavy_plus_sign: Add glint and argv as dependencies. * :sparkles: Use glint for cli args parsing. This adds support for user-configurable host and port, as well as the ability to opt-in to including lustre_ui's stylesheet with the --include-styles flag.
Diffstat (limited to 'src/http_ffi.erl')
-rw-r--r--src/http_ffi.erl13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/http_ffi.erl b/src/http_ffi.erl
index e9de7e7..355fabd 100644
--- a/src/http_ffi.erl
+++ b/src/http_ffi.erl
@@ -1,7 +1,7 @@
-module(http_ffi).
--export([serve/4, response_default_headers/0]).
+-export([serve/3, response_default_headers/0]).
-serve(Host, Port, OnStart, OnPortTaken) ->
+serve({options, Host, Port, IncludeStyles}, OnStart, OnPortTaken) ->
{ok, Pattern} = re:compile("name *= *\"(?<Name>.+)\""),
{ok, Toml} = file:read_file("gleam.toml"),
{match, [Name]} = re:run(Toml, Pattern, [{capture, all_names, binary}]),
@@ -13,8 +13,13 @@ serve(Host, Port, OnStart, OnPortTaken) ->
"<head>\n"
" <meta charset=\"UTF-8\">\n"
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n"
- " <title>Lustre preview server</title>\n"
- "\n"
+ " <title>Lustre preview server</title>\n",
+ case IncludeStyles of
+ true ->
+ <<" <link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/gh/lustre-labs/ui/priv/styles.css\">\n">>;
+ false ->
+ <<"">>
+ end/binary,
" <script type=\"module\">\n"
" import { main } from './",
Name/binary,