Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: basepath routing for DevServer vhost emulation #59

Merged
merged 10 commits into from
Jan 8, 2024
6 changes: 5 additions & 1 deletion lib/mix/tasks/tableau.server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ defmodule Mix.Tasks.Tableau.Server do
Application.put_env(:tableau, :server, true)
Code.put_compiler_option(:ignore_module_conflict, true)

Logger.debug("server started on http://localhost:4999")
Logger.debug("server started on http://localhost:4999#{basepath()}")

Mix.Task.run("app.start", ["--preload-modules"])

Mix.Tasks.Run.run(["--no-halt"])
end

defp basepath do
Path.join("/", Application.get_env(:tableau, :config)[:base_path] || "")
end
end
1 change: 1 addition & 0 deletions lib/tableau.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule Tableau do

* `:include_dir` - string - Directory that is just copied to the output directory. Defaults to `extra`.
* `:timezone` - string - Timezone to use when parsing date times. Defaults to `Etc/UTC`.
* `:base_path - string - Development server root. Defaults to '/'.
* `:url` - string (required) - The URL of your website.
* `:markdown` - keyword
* `:mdex` - keyword - Options to pass to `MDEx.to_html/2`
Expand Down
1 change: 1 addition & 0 deletions lib/tableau/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule Tableau.Config do

defstruct [
:url,
base_path: "",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add documentation for this. Its in the Tableau moduledoc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

include_dir: "extra",
timezone: "Etc/UTC",
reload_log: false,
Expand Down
4 changes: 3 additions & 1 deletion lib/tableau/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ defmodule Tableau.Router do

require Logger

@base_path Path.join("/", Application.compile_env(:tableau, [:config, :base_path], ""))

@not_found ~g'''
<!DOCTYPE html><html lang="en"><head></head><body>Not Found</body></html>
'''html
Expand All @@ -14,7 +16,7 @@ defmodule Tableau.Router do
plug :rerender

plug Tableau.IndexHtml
plug Plug.Static, at: "/", from: "_site", cache_control_for_etags: "no-cache"
plug Plug.Static, at: @base_path, from: "_site", cache_control_for_etags: "no-cache"

plug :match
plug :dispatch
Expand Down