mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-20 20:36:19 +02:00
🔗 Add support for shorter urls (#750)
This commit is contained in:
parent
30a1136529
commit
2e5468ed65
5 changed files with 16 additions and 5 deletions
|
@ -12,6 +12,8 @@ const PORT = process.env.PORT || 3000;
|
||||||
// Set webServer.url and use.baseURL with the location of the WebServer respecting the correct set port
|
// Set webServer.url and use.baseURL with the location of the WebServer respecting the correct set port
|
||||||
const baseURL = `http://localhost:${PORT}`;
|
const baseURL = `http://localhost:${PORT}`;
|
||||||
|
|
||||||
|
process.env.NEXT_PUBLIC_BASE_URL = baseURL;
|
||||||
|
|
||||||
// Reference: https://playwright.dev/docs/test-configuration
|
// Reference: https://playwright.dev/docs/test-configuration
|
||||||
const config: PlaywrightTestConfig = {
|
const config: PlaywrightTestConfig = {
|
||||||
// Artifacts folder where screenshots, videos, and traces are stored.
|
// Artifacts folder where screenshots, videos, and traces are stored.
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
DialogTrigger,
|
DialogTrigger,
|
||||||
} from "@rallly/ui/dialog";
|
} from "@rallly/ui/dialog";
|
||||||
|
import { shortUrl } from "@rallly/utils";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { useCopyToClipboard } from "react-use";
|
import { useCopyToClipboard } from "react-use";
|
||||||
|
@ -29,7 +30,7 @@ export const InviteDialog = () => {
|
||||||
}
|
}
|
||||||
}, [state]);
|
}, [state]);
|
||||||
|
|
||||||
const inviteLink = `${window.location.origin}/invite/${poll?.id}`;
|
const inviteLink = shortUrl(`/invite/${poll?.id}`);
|
||||||
const [didCopy, setDidCopy] = React.useState(false);
|
const [didCopy, setDidCopy] = React.useState(false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { prisma } from "@rallly/database";
|
import { prisma } from "@rallly/database";
|
||||||
import { sendEmail } from "@rallly/emails";
|
import { sendEmail } from "@rallly/emails";
|
||||||
import { absoluteUrl } from "@rallly/utils";
|
import { absoluteUrl, shortUrl } from "@rallly/utils";
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import timezone from "dayjs/plugin/timezone";
|
import timezone from "dayjs/plugin/timezone";
|
||||||
|
@ -140,7 +140,7 @@ export const polls = router({
|
||||||
? absoluteUrl(`/admin/${adminToken}`)
|
? absoluteUrl(`/admin/${adminToken}`)
|
||||||
: absoluteUrl(`/poll/${pollId}`);
|
: absoluteUrl(`/poll/${pollId}`);
|
||||||
|
|
||||||
const participantLink = absoluteUrl(`/invite/${pollId}`);
|
const participantLink = shortUrl(`/invite/${pollId}`);
|
||||||
|
|
||||||
if (email && name) {
|
if (email && name) {
|
||||||
await sendEmail("NewPollEmail", {
|
await sendEmail("NewPollEmail", {
|
||||||
|
|
|
@ -6,10 +6,17 @@ const getVercelUrl = () => {
|
||||||
: null;
|
: null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function absoluteUrl(path = "") {
|
export function absoluteUrl(subpath = "") {
|
||||||
const baseUrl =
|
const baseUrl =
|
||||||
process.env.NEXT_PUBLIC_BASE_URL ??
|
process.env.NEXT_PUBLIC_BASE_URL ??
|
||||||
getVercelUrl() ??
|
getVercelUrl() ??
|
||||||
`http://localhost:${port}`;
|
`http://localhost:${port}`;
|
||||||
return `${baseUrl}${path}`;
|
const url = new URL(subpath, baseUrl);
|
||||||
|
return url.href;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function shortUrl(subpath = "") {
|
||||||
|
const baseUrl = process.env.NEXT_PUBLIC_SHORT_BASE_URL ?? absoluteUrl();
|
||||||
|
const url = new URL(subpath, baseUrl);
|
||||||
|
return url.href;
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@
|
||||||
"EMAIL_PROVIDER",
|
"EMAIL_PROVIDER",
|
||||||
"MAINTENANCE_MODE",
|
"MAINTENANCE_MODE",
|
||||||
"NEXT_PUBLIC_APP_BASE_URL",
|
"NEXT_PUBLIC_APP_BASE_URL",
|
||||||
|
"NEXT_PUBLIC_SHORT_BASE_URL",
|
||||||
"NEXT_PUBLIC_APP_VERSION",
|
"NEXT_PUBLIC_APP_VERSION",
|
||||||
"NEXT_PUBLIC_BASE_URL",
|
"NEXT_PUBLIC_BASE_URL",
|
||||||
"NEXT_PUBLIC_BETA",
|
"NEXT_PUBLIC_BETA",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue