Skip to content

Commit

Permalink
fix port/location calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed May 10, 2024
1 parent a2e83c0 commit 92bc392
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Go to the `v1` branch to see the changelog of Lume 1.
- For better predictability, the `_cache` folder is generated in the root folder, instead of `src` folder.
- Simplified Esbuild plugin.
- Import `std` packages from `jsr` because they are not longer updated on `land/x`.
- The default port when lume build the site (not serving) is `80` or `443`, depending whether the location protocol is http or https. Previously it was `3000`.

### Deprecated
- `liquid` plugin. It never worked well with `search.pages()` [#600].
Expand Down
1 change: 0 additions & 1 deletion core/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ export default class Site {

constructor(options: Partial<SiteOptions> = {}) {
this.options = merge(defaults, options);
this.options.location.port ||= this.options.server.port.toString();

const src = this.src();
const dest = this.dest();
Expand Down
34 changes: 26 additions & 8 deletions core/utils/cli_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,38 @@ export function getOptionsFromCli(
options.dest = cli.dest;
}

if (cli.port) {
(options.server ||= {}).port = parseInt(cli.port);
} else if (cli.serve) {
(options.server ||= {}).port = 3000;
}

let location: URL;

if (cli.location) {
options.location = new URL(cli.location);
} else if (cli.serve || cli._[0] === "cms") {
options.location = new URL(`http://localhost:${cli.port || 3000}/`);
location = new URL(cli.location);
} else if (options.location && !cli.server) {
location = options.location as URL;
} else {
location = new URL("http://localhost");
}

if (cli.port) {
(options.server ||= {}).port = parseInt(cli.port);
let port: number;

if (options.location) {
options.location.port = cli.port;
}
if (cli.port) {
port = parseInt(cli.port);
} else if (location.port) {
port = parseInt(location.port);
} else if (options.server?.port) {
port = options.server.port;
} else {
port = cli.serve ? 3000 : location.protocol === "https:" ? 443 : 80;
}

(options.server ||= {}).port = port;
location.port = port.toString();
options.location = location;

if (cli.open) {
(options.server ||= {}).open = cli.open;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Deno.test("default configuration", () => {
equals(options.dest, "./_site");
equals(options.location.href, "http://localhost/");
equals(options.prettyUrls, true);
equals(options.server.port, 3000);
equals(options.server.port, 80);
equals(options.server.page404, "/404.html");
equals(options.server.open, false);
});
Expand Down

0 comments on commit 92bc392

Please sign in to comment.