Skip to content

Commit

Permalink
fix: respect custom host in local dev (#1122)
Browse files Browse the repository at this point in the history
Fixes #1121
  • Loading branch information
Skn0tt committed Feb 16, 2023
1 parent df8f4b2 commit 71304ff
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/cli/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export async function runQuirrelDev(
}

await quirrel.server.app.jobs.updateCron("anonymous", {
baseUrl: getApplicationBaseUrl(),
baseUrl: getApplicationBaseUrl(config.host),
crons: jobs,
});
});
Expand Down
14 changes: 7 additions & 7 deletions src/client/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function getOldEncryptionSecrets(): string[] | null {
return JSON.parse(process.env.QUIRREL_OLD_SECRETS ?? "null");
}

let developmentApplicationBaseUrl: string | undefined;
let developmentApplicationPort: number | undefined;

function getNetlifyURL() {
const siteId = process.env.SITE_ID;
Expand All @@ -108,12 +108,12 @@ function getVercelURL() {
return process.env.VERCEL_URL;
}

export function getApplicationBaseUrl(): string {
export function getApplicationBaseUrl(host = "localhost"): string {
const baseUrl =
resolveEnvReference("QUIRREL_BASE_URL") ||
getNetlifyURL() ||
getVercelURL() ||
developmentApplicationBaseUrl;
`http://${host}:${developmentApplicationPort}`;

if (!baseUrl) {
throw new Error("Please specify QUIRREL_BASE_URL.");
Expand All @@ -123,17 +123,17 @@ export function getApplicationBaseUrl(): string {
}

export function registerDevelopmentDefaults({
applicationBaseUrl,
applicationPort,
}: {
applicationBaseUrl: string;
applicationPort: number;
}) {
if (isProduction()) {
return;
}

if (developmentApplicationBaseUrl) {
if (developmentApplicationPort) {
return;
}

developmentApplicationBaseUrl = applicationBaseUrl;
developmentApplicationPort = applicationPort;
}
2 changes: 1 addition & 1 deletion src/netlify.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { registerDevelopmentDefaults } from "./client/config";

registerDevelopmentDefaults({
applicationBaseUrl: "http://localhost:8888",
applicationPort: 8888,
});

export * from "./redwood";
2 changes: 1 addition & 1 deletion src/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export {
};

registerDevelopmentDefaults({
applicationBaseUrl: "http://localhost:3000",
applicationPort: 3000,
});

export type Queue<Payload> = Omit<
Expand Down
2 changes: 1 addition & 1 deletion src/nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { registerDevelopmentDefaults } from "./client/config";
import * as connect from "./connect";

registerDevelopmentDefaults({
applicationBaseUrl: "http://localhost:3000",
applicationPort: 3000,
});

export function Queue<Payload>(
Expand Down
2 changes: 1 addition & 1 deletion src/redwood.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export {
};

registerDevelopmentDefaults({
applicationBaseUrl: "http://localhost:8911",
applicationPort: 8911,
});

function decodeBase64(v: string): string {
Expand Down
2 changes: 1 addition & 1 deletion src/remix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export {
};

registerDevelopmentDefaults({
applicationBaseUrl: "http://localhost:3000",
applicationPort: 3000,
});

export type Queue<Payload> = Omit<
Expand Down
2 changes: 1 addition & 1 deletion src/sveltekit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { registerDevelopmentDefaults } from "./client/config";
export { Job, EnqueueJobOptions, DefaultJobOptions, QuirrelJobHandler };

registerDevelopmentDefaults({
applicationBaseUrl: "localhost:5173",
applicationPort: 5173,
});

interface SvelteEvent {
Expand Down

0 comments on commit 71304ff

Please sign in to comment.