diff --git a/docs/configs.md b/docs/configs.md index db636c3e1..9caa98aee 100644 --- a/docs/configs.md +++ b/docs/configs.md @@ -35,3 +35,39 @@ Valid values for `homepage`: `pages` (default), `posts`, ``, jekyll_admin: homepage: "posts" ``` + +#### `host` + +For overriding `host` from the Jekyll installation. + +This can be useful if Jekyll Admin is behind a reverse proxy. + +```yaml +host: "mydomain.com" +jekyll_admin: + host: "admin.mydomain.com" +``` + +#### `port` + +For overriding `port` from the Jekyll installation. + +This can be useful if Jekyll Admin is behind a reverse proxy. + +```yaml +port: 4000 +jekyll_admin: + port: 4001 +``` + +#### `scheme` + +For overriding `scheme` from the Jekyll installation. + +This can be useful if Jekyll Admin is behind a reverse proxy. + +```yaml +scheme: "https" +jekyll_admin: + scheme: "http" +``` diff --git a/lib/jekyll-admin/urlable.rb b/lib/jekyll-admin/urlable.rb index b311dde82..a248f170f 100644 --- a/lib/jekyll-admin/urlable.rb +++ b/lib/jekyll-admin/urlable.rb @@ -61,15 +61,19 @@ def path_with_base(base, path) end def scheme - JekyllAdmin.site.config["scheme"] || "http" + JekyllAdmin.site.config.dig("jekyll_admin", "scheme") || + JekyllAdmin.site.config["scheme"] || + "http" end def host - JekyllAdmin.site.config["host"].sub("127.0.0.1", "localhost") + JekyllAdmin.site.config.dig("jekyll_admin", "host") || + JekyllAdmin.site.config["host"].sub("127.0.0.1", "localhost") end def port - JekyllAdmin.site.config["port"] + JekyllAdmin.site.config.dig("jekyll_admin", "port") || + JekyllAdmin.site.config["port"] end end end diff --git a/spec/jekyll-admin/urlable_spec.rb b/spec/jekyll-admin/urlable_spec.rb index 83074a68b..e68f41721 100644 --- a/spec/jekyll-admin/urlable_spec.rb +++ b/spec/jekyll-admin/urlable_spec.rb @@ -8,16 +8,36 @@ let(:prefix) { "_api" } let(:url_base) { "#{scheme}://#{host}:#{port}" } - it "knows the host" do - expect(subject.send(:host)).to eql("localhost") - end + context "with custom configuration" do + it "knows the jekyll_admin host" do + JekyllAdmin.site.config["jekyll_admin"]["host"] = "foo" + expect(subject.send(:host)).to eql("foo") + JekyllAdmin.site.config["jekyll_admin"]["host"] = nil + end - it "knows the port" do - expect(subject.send(:port)).to eql("4000") - end + it "knows the base host" do + expect(subject.send(:host)).to eql("localhost") + end + + it "knows the jekyll_admin port" do + JekyllAdmin.site.config["jekyll_admin"]["port"] = 1000 + expect(subject.send(:port)).to eql(1000) + JekyllAdmin.site.config["jekyll_admin"]["port"] = nil + end - it "knows the scheme" do - expect(subject.send(:scheme)).to eql("http") + it "knows the port" do + expect(subject.send(:port)).to eql("4000") + end + + it "knows the jekyll_admin scheme" do + JekyllAdmin.site.config["jekyll_admin"]["scheme"] = "baz" + expect(subject.send(:scheme)).to eql("baz") + JekyllAdmin.site.config["jekyll_admin"]["scheme"] = nil + end + + it "knows the scheme" do + expect(subject.send(:scheme)).to eql("http") + end end context "pages" do