Skip to content

Commit 7afa7e0

Browse files
fix: enable workers.dev route (#135)
1 parent 697014f commit 7afa7e0

24 files changed

Lines changed: 218 additions & 123 deletions

File tree

‎apps/web/.env.development.example‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# Drizzle / libSQL (local sqlite)
55
DATABASE_URL=file:./local.db
66
TURSO_AUTH_TOKEN=
7-
NEXT_PUBLIC_APP_URL=http://localhost:3000
87
BETTER_AUTH_SECRET=dev-secret-please-change-dev-secret-32ch
98

109
# OAuth (optional)

‎apps/web/.env.production.example‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# Drizzle / libSQL (Turso)
55
DATABASE_URL=libsql://<db-name>-<org>.turso.io
66
TURSO_AUTH_TOKEN=
7-
NEXT_PUBLIC_APP_URL=https://<your-domain>
87
BETTER_AUTH_SECRET=
98

109
# OAuth (optional)

‎apps/web/next.config.js‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,6 @@ import { initOpenNextCloudflareForDev } from '@opennextjs/cloudflare';
22

33
initOpenNextCloudflareForDev();
44

5-
const appUrl = process.env.NEXT_PUBLIC_APP_URL
6-
? new URL(process.env.NEXT_PUBLIC_APP_URL)
7-
: null;
8-
9-
const appImageRemotePatterns = appUrl
10-
? [
11-
{
12-
protocol: appUrl.protocol.replace(':', ''),
13-
hostname: appUrl.hostname,
14-
port: appUrl.port,
15-
pathname: '/api/files/**',
16-
},
17-
]
18-
: [];
19-
205
/** @type {import('next').NextConfig} */
216
const nextConfig = {
227
reactStrictMode: true,
@@ -30,7 +15,6 @@ const nextConfig = {
3015
protocol: 'http',
3116
hostname: 'localhost',
3217
},
33-
...appImageRemotePatterns,
3418
],
3519
},
3620
transpilePackages: [

‎apps/web/package.json‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"private": true,
55
"type": "module",
66
"scripts": {
7-
"build": "next build",
8-
"build:worker": "opennextjs-cloudflare build",
7+
"build": "SKIP_ENV_VALIDATION=true next build",
8+
"build:worker": "SKIP_ENV_VALIDATION=true opennextjs-cloudflare build",
99
"cf-typegen": "wrangler types --env-interface CloudflareEnv cloudflare-env.d.ts",
10-
"deploy": "opennextjs-cloudflare build && opennextjs-cloudflare deploy",
10+
"deploy": "SKIP_ENV_VALIDATION=true opennextjs-cloudflare build && opennextjs-cloudflare deploy",
1111
"dev": "next dev -p 3000",
1212
"lint": "eslint . --cache --max-warnings 0",
13-
"preview": "opennextjs-cloudflare build && opennextjs-cloudflare preview",
13+
"preview": "SKIP_ENV_VALIDATION=true opennextjs-cloudflare build && opennextjs-cloudflare preview",
1414
"start": "next start",
1515
"typecheck": "tsc --noEmit --tsBuildInfoFile .tsbuildinfo"
1616
},

‎apps/web/src/app/(landing)/layout.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ async function LandingPageLayout({ children }: { children: ReactNode }) {
1010
const databaseUrl = process.env['DATABASE_URL'];
1111
const hasSessionRuntimeEnv =
1212
!!databaseUrl &&
13-
(!databaseUrl.startsWith('libsql://') || !!process.env['TURSO_AUTH_TOKEN']) &&
13+
(!databaseUrl.startsWith('libsql://') ||
14+
!!process.env['TURSO_AUTH_TOKEN']) &&
1415
!!process.env['BETTER_AUTH_SECRET'] &&
15-
!!process.env['NEXT_PUBLIC_APP_URL'] &&
1616
!!process.env['ALLOW_SIGNIN_SIGNUP'];
1717
let isLoggedIn = false;
1818

‎apps/web/src/app/(main)/dashboard/page.tsx‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import * as React from 'react';
22
import { type Metadata } from 'next';
33

4-
import { env } from '@formbase/env';
5-
64
import { api } from '~/lib/trpc/server';
75

86
import { Forms } from './_components/forms';
97
import { CreateFormDialog } from './_components/new-form-dialog';
108
import { FormsSkeleton } from './_components/posts-skeleton';
119

1210
export const metadata: Metadata = {
13-
metadataBase: new URL(env.NEXT_PUBLIC_APP_URL),
1411
title: 'Forms',
1512
description: 'Manage your form endpoints',
1613
};

‎apps/web/src/app/(main)/dashboard/settings/api-keys/page.tsx‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ import { redirect } from 'next/navigation';
33
import type { Metadata } from 'next';
44

55
import { getSession } from '@formbase/auth/server';
6-
import { env } from '@formbase/env';
76
import { Separator } from '@formbase/ui/primitives/separator';
87

98
import { ApiKeysSection } from './api-keys-section';
109

1110
export const metadata: Metadata = {
12-
metadataBase: new URL(env.NEXT_PUBLIC_APP_URL),
1311
title: 'API Keys | Formbase',
1412
description: 'Manage your API keys for programmatic access',
1513
};

‎apps/web/src/app/(main)/dashboard/settings/page.tsx‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ import { redirect } from 'next/navigation';
33
import type { Metadata } from 'next';
44

55
import { getSession } from '@formbase/auth/server';
6-
import { env } from '@formbase/env';
76
import { Separator } from '@formbase/ui/primitives/separator';
87

98
import { ProfileForm } from './profile-form';
109

1110
export const metadata: Metadata = {
12-
metadataBase: new URL(env.NEXT_PUBLIC_APP_URL),
1311
title: 'Settings | Formbase',
1412
description: 'Manage your account settings',
1513
};

‎apps/web/src/app/api/s/[id]/route.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { userAgent } from 'next/server';
22

33
import { type RouterOutputs } from '@formbase/api';
4-
import { env } from '@formbase/env';
54

65
import { sendMail } from '~/lib/email/mailer';
76
import { renderNewSubmissionEmail } from '~/lib/email/templates/new-submission';
@@ -64,14 +63,15 @@ async function getFormData(request: Request): Promise<FormDataResult> {
6463
async function processFileUploads(
6564
formData: Record<string, Blob | string | undefined>,
6665
formDataFromRequest: FormData,
66+
requestOrigin: string,
6767
) {
6868
const fileKeys = Object.keys(formData).filter(
6969
(key) => formData[key] instanceof Blob,
7070
);
7171

7272
for (const key of fileKeys) {
7373
const file = formDataFromRequest.get(key) as File;
74-
const fileUrl = await uploadFileFromBlob({ file });
74+
const fileUrl = await uploadFileFromBlob({ file, origin: requestOrigin });
7575
assignFileOrImage({ formData, key, fileUrl });
7676
}
7777
}
@@ -103,6 +103,7 @@ export async function POST(
103103
const { id } = await params;
104104

105105
const formId = id;
106+
const requestOrigin = new URL(request.url).origin;
106107
const form = await api.form.getFormById({ formId });
107108
if (!form) {
108109
return new Response('Form not found', {
@@ -117,7 +118,11 @@ export async function POST(
117118
const { data: formData } = formDataResult;
118119

119120
if (formDataResult.source === 'formData') {
120-
await processFileUploads(formData, formDataResult.rawFormData);
121+
await processFileUploads(
122+
formData,
123+
formDataResult.rawFormData,
124+
requestOrigin,
125+
);
121126
}
122127

123128
const honeypotField = form.honeypotField;
@@ -158,7 +163,7 @@ export async function POST(
158163
return new Response(null, {
159164
status: 303,
160165
headers: {
161-
Location: `${env.NEXT_PUBLIC_APP_URL}/s/${formId}`,
166+
Location: new URL(`/s/${formId}`, requestOrigin).toString(),
162167
...CORS_HEADERS,
163168
},
164169
});

‎apps/web/src/app/api/v1/openapi.json/route.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { generateOpenApiDocument } from 'trpc-to-openapi';
22

33
import { apiV1Router } from '@formbase/api/routers/api-v1';
4-
import { env } from '@formbase/env';
54

65
export const dynamic = 'force-dynamic';
76

8-
export function GET() {
7+
export function GET(request: Request) {
98
const openApiDocument = generateOpenApiDocument(apiV1Router, {
109
title: 'Formbase API',
1110
version: '1.0.0',
12-
baseUrl: `${env.NEXT_PUBLIC_APP_URL}/api/v1`,
11+
baseUrl: `${new URL(request.url).origin}/api/v1`,
1312
description: 'Public REST API for managing forms and submissions.',
1413
securitySchemes: {
1514
bearerAuth: {

0 commit comments

Comments
 (0)