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

Add option to set admin specific scheme/host/port #684

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions docs/configs.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,39 @@ Valid values for `homepage`: `pages` (default), `posts`, `<collection_name>`,
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"
```
10 changes: 7 additions & 3 deletions lib/jekyll-admin/urlable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 28 additions & 8 deletions spec/jekyll-admin/urlable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down