Fixed https missing from url
This commit is contained in:
+2
-2
@@ -30,7 +30,7 @@ import {
|
||||
EnvironmentsPresenter,
|
||||
} from "~/presenters/EnvironmentsPresenter.server";
|
||||
import { requireUserId } from "~/services/session.server";
|
||||
import { formatDateTime } from "~/utils";
|
||||
import { formatDateTime, requestUrl } from "~/utils";
|
||||
import { Handle } from "~/utils/handle";
|
||||
import { ProjectParamSchema } from "~/utils/pathBuilder";
|
||||
import { RuntimeEnvironmentType } from "../../../../../packages/database/src";
|
||||
@@ -41,7 +41,7 @@ export const loader = async ({ request, params }: LoaderArgs) => {
|
||||
const { projectParam } = ProjectParamSchema.parse(params);
|
||||
|
||||
try {
|
||||
const url = new URL(request.url);
|
||||
const url = requestUrl(request);
|
||||
const baseUrl = `${url.protocol}//${url.host}`;
|
||||
const presenter = new EnvironmentsPresenter();
|
||||
const { environments, clients } = await presenter.call({
|
||||
|
||||
@@ -12,22 +12,22 @@ import { FormTitle } from "~/components/primitives/FormTitle";
|
||||
import { NamedIcon } from "~/components/primitives/NamedIcon";
|
||||
import { Paragraph, TextLink } from "~/components/primitives/Paragraph";
|
||||
import { isGithubAuthSupported } from "~/services/auth.server";
|
||||
|
||||
import { commitSession, setRedirectTo } from "~/services/redirectTo.server";
|
||||
import { getUserId } from "~/services/session.server";
|
||||
import { requestUrl } from "~/utils";
|
||||
|
||||
export async function loader({ request }: LoaderArgs) {
|
||||
const userId = await getUserId(request);
|
||||
if (userId) return redirect("/");
|
||||
|
||||
const url = new URL(request.url);
|
||||
const url = requestUrl(request);
|
||||
const redirectTo = url.searchParams.get("redirectTo");
|
||||
|
||||
if (redirectTo) {
|
||||
const session = await setRedirectTo(request, redirectTo);
|
||||
|
||||
return typedjson(
|
||||
{ redirectTo, isGithubAuthSupported },
|
||||
{ redirectTo, showGithubAuth: isGithubAuthSupported },
|
||||
{
|
||||
headers: {
|
||||
"Set-Cookie": await commitSession(session),
|
||||
@@ -35,7 +35,10 @@ export async function loader({ request }: LoaderArgs) {
|
||||
}
|
||||
);
|
||||
} else {
|
||||
return typedjson({ redirectTo: null, isGithubAuthSupported });
|
||||
return typedjson({
|
||||
redirectTo: null,
|
||||
showGithubAuth: isGithubAuthSupported,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +67,7 @@ export default function LoginPage() {
|
||||
<FormTitle divide={false} title="Create your Trigger.dev account" />
|
||||
<Fieldset>
|
||||
<div className="flex flex-col gap-y-2">
|
||||
{isGithubAuthSupported && (
|
||||
{data.showGithubAuth && (
|
||||
<Button type="submit" variant="primary/large" fullWidth>
|
||||
<NamedIcon name={"github"} className={"mr-1.5 h-4 w-4"} />
|
||||
Continue with GitHub
|
||||
|
||||
@@ -6,6 +6,7 @@ import { env } from "~/env.server";
|
||||
import { integrationAuthRepository } from "~/services/externalApis/integrationAuthRepository.server";
|
||||
import { OAuthClient, OAuthClientSchema } from "~/services/externalApis/types";
|
||||
import { getSecretStore } from "~/services/secrets/secretStore.server";
|
||||
import { requestUrl } from "~/utils";
|
||||
|
||||
const ParamsSchema = z
|
||||
.object({
|
||||
@@ -20,7 +21,7 @@ export async function loader({ request }: LoaderArgs) {
|
||||
return { status: 405, body: "Method Not Allowed" };
|
||||
}
|
||||
|
||||
const url = new URL(request.url);
|
||||
const url = requestUrl(request);
|
||||
const parsedParams = ParamsSchema.safeParse(
|
||||
Object.fromEntries(url.searchParams)
|
||||
);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { PrismaClient } from "~/db.server";
|
||||
import { prisma } from "~/db.server";
|
||||
import { workerQueue } from "../worker.server";
|
||||
import { requestUrl } from "~/utils";
|
||||
|
||||
export class HandleHttpSourceService {
|
||||
#prismaClient: PrismaClient;
|
||||
@@ -10,6 +11,8 @@ export class HandleHttpSourceService {
|
||||
}
|
||||
|
||||
public async call(id: string, request: Request) {
|
||||
const url = requestUrl(request);
|
||||
|
||||
const triggerSource = await this.#prismaClient.triggerSource.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
@@ -35,7 +38,7 @@ export class HandleHttpSourceService {
|
||||
sourceId: triggerSource.id,
|
||||
endpointId: triggerSource.endpointId,
|
||||
environmentId: triggerSource.environmentId,
|
||||
url: request.url,
|
||||
url: url.href,
|
||||
method: request.method,
|
||||
headers: Object.fromEntries(request.headers),
|
||||
body: ["POST", "PUT", "PATCH"].includes(request.method)
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import {
|
||||
ErrorWithStack,
|
||||
ErrorWithStackSchema,
|
||||
} from "@trigger.dev/internal";
|
||||
import { ErrorWithStack, ErrorWithStackSchema } from "@trigger.dev/internal";
|
||||
import type { RouteMatch } from "@remix-run/react";
|
||||
import { useMatches } from "@remix-run/react";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
@@ -214,3 +211,16 @@ export function formatUnknownError(
|
||||
|
||||
return "Unknown error";
|
||||
}
|
||||
|
||||
// This will read the X-Forwarded-Proto header from the request, and make sure the
|
||||
// returned url has the matching proto if the request.url does not
|
||||
export function requestUrl(request: Request): URL {
|
||||
const url = new URL(request.url);
|
||||
const proto = request.headers.get("X-Forwarded-Proto");
|
||||
|
||||
if (proto && url.protocol !== proto) {
|
||||
url.protocol = proto;
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user