Hi all! I am trying to point multiple domain’s DNS records to my private server.
This server will be running cowboy which will, hopefully, grab the hostname included within the request and serve the appropriate website files.
However, I am having a heck of a time trying to get css/js to deliver consistently–it 404’s constantly.
For context, here is the file structure:
priv/
-sites/
--localhost/
---static/
----assets/
-----css/
-----js/
---templates/
----default/
-----home.html
----reader/
-----home.html
----viewer/
-----home.html
And then the code responsible for routing:
init([]) ->
{ok, Cwd} = file:get_cwd(),
StaticPath = filename:join([Cwd, "priv", "sites", "localhost", "static"]),
Dispatch = cowboy_router:compile([
{'_', [
{"/", page_handler, []},
{"/static/assets/[...]", cowboy_static, % Change to match exact path
{priv_dir, StaticPath ++ "/assets", % Use exact directory
[{mimetypes, cow_mimetypes, all}]}},
{"/page/:id", page_handler, []}
]}
]),
{ok, _} = cowboy:start_clear(
http_listener,
[{port, 8080}],
#{env => #{dispatch => Dispatch}}
),
{ok, {{one_for_one, 5, 10}, []}}.
It appears as if the main issue is that I cannot get access the requested hostname and, instead, have had to hardcode localhost… which doesn’t allow me to serve multiple site files like I want.
I could also be approaching this totally wrong, I’m new and trying, so please be nice haha