Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
450 changes: 0 additions & 450 deletions .plans/files-gateway-asset-index.md

This file was deleted.

6 changes: 3 additions & 3 deletions apps/api/.env.template
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# ===========PROJECT===========
# Add specific project environment variables here

BASE_URL="http://localhost:3000"
ALLOWED_API_ORIGINS="http://localhost:3001"
BASE_URL="https://api.init.localhost"
ALLOWED_API_ORIGINS="https://init.localhost"
PORT="3000"

# --- Files SDK / S3 ---
Expand All @@ -18,7 +18,7 @@ S3_SECRET_ACCESS_KEY="minioadmin"

# --- Auth (@init/env/auth) ---
AUTH_SECRET="dev-secret"
AUTH_TRUSTED_ORIGINS="http://localhost:3001,http://localhost:3000"
AUTH_TRUSTED_ORIGINS="https://init.localhost,https://api.init.localhost"

# --- Auth Providers (@init/env/auth/providers) ---
# GitHub OAuth
Expand Down
7 changes: 6 additions & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"bump:deps": "bun update --interactive",
"clean": "git clean -xdf .cache .turbo dist node_modules",
"codegen": "paraglide-js compile --project ../../tooling/internationalization/project.inlang --outdir ./src/shared/internationalization",
"dev": "bun --hot src/index.ts",
"dev": "portless",
"dev:app": "bun --hot src/index.ts",
"start": "bun --bun src/index.ts"
},
"dependencies": {
Expand Down Expand Up @@ -43,5 +44,9 @@
"@tooling/tsconfig": "workspace:*",
"@types/bun": "1.3.14",
"typescript": "7.0.2"
},
"portless": {
"name": "api.init",
"script": "dev:app"
}
}
4 changes: 2 additions & 2 deletions apps/api/src/routes/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import type { AuthenticatedAppContext } from "#shared/types.ts"
import env from "#shared/env.ts"
import { files, FILES_MAX_UPLOAD_SIZE, FILES_MAX_URL_AGE } from "#shared/files.ts"
import { requireSession } from "#shared/middleware.ts"
import { context, factory } from "#shared/utils.ts"
import { allowedOrigins, context, factory } from "#shared/utils.ts"

const router = createFilesRouter({
allowedOrigins: env.ALLOWED_API_ORIGINS,
allowedOrigins,
authorize: () => {
const ctx = context<AuthenticatedAppContext>()

Expand Down
5 changes: 2 additions & 3 deletions apps/api/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ import trpcRoutes from "#routes/trpc.ts"
import v1Routes from "#routes/v1/index.ts"
import workflowRoutes from "#routes/workflows.ts"
import { auth } from "#shared/auth.ts"
import env from "#shared/env.ts"
import { files } from "#shared/files.ts"
import { LoggerCategory, logger } from "#shared/logger.ts"
import { withLanguageDetection } from "#shared/middleware.ts"
import { factory } from "#shared/utils.ts"
import { allowedOrigins, factory } from "#shared/utils.ts"

const app = factory.createApp()

Expand All @@ -37,7 +36,7 @@ app.use(
credentials: true,
exposeHeaders: ["Content-Length"],
maxAge: 600,
origin: env.ALLOWED_API_ORIGINS,
origin: allowedOrigins,
})
)

Expand Down
5 changes: 3 additions & 2 deletions apps/api/src/shared/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import { database } from "@init/db/client"
import { sendEmail } from "@init/email/client"
import PasswordReset from "@init/email/templates/password-reset"
import env from "#shared/env.ts"
import { allowedOrigins, baseUrl } from "#shared/utils.ts"

export const auth = createAuth({
advanced: AUTH_ADVANCED_OPTIONS,
appName: AUTH_APP_NAME,
basePath: "/auth",
baseURL: env.BASE_URL,
baseURL: baseUrl,
database: databaseAdapter(database()),
emailAndPassword: {
...AUTH_EMAIL_AND_PASSWORD_OPTIONS,
Expand All @@ -41,7 +42,7 @@ export const auth = createAuth({
enabled: true,
},
},
trustedOrigins: env.ALLOWED_API_ORIGINS,
trustedOrigins: allowedOrigins,
})

export type Auth = typeof auth
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/shared/env.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createEnv } from "@init/env"
import { auth, db, inngest, kv, resend, s3, sentry } from "@init/env/presets"
import { auth, db, inngest, kv, portless, resend, s3, sentry } from "@init/env/presets"
import * as z from "@init/utils/schema"
import { isCI } from "std-env"

Expand All @@ -11,6 +11,7 @@ export default createEnv({
auth.providers.google(),
db(),
kv(),
portless(),
inngest(),
resend(),
s3(),
Expand Down
13 changes: 13 additions & 0 deletions apps/api/src/shared/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import { getContext } from "hono/context-storage"
import { createFactory } from "hono/factory"
import type { AppContext } from "#shared/types.ts"
import env from "#shared/env.ts"

export const baseUrl = env.PORTLESS_URL ?? env.BASE_URL

export const allowedOrigins = env.PORTLESS_URL
? env.ALLOWED_API_ORIGINS.map(
(origin) =>
new URL(
env.PORTLESS_URL?.replace(new URL(env.BASE_URL).hostname, new URL(origin).hostname) ??
origin
).origin
Comment on lines +12 to +14

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve legacy local origins when Portless is active

When an existing checkout retains the previous .env.local values (BASE_URL=http://localhost:3000 and ALLOWED_API_ORIGINS=http://localhost:3001), Portless supplies https://api.init.localhost here, but replacing localhost with the identical origin hostname leaves the API URL unchanged. allowedOrigins therefore becomes the API's own origin rather than https://init.localhost, causing CORS, Better Auth, and Files SDK requests from the App to be rejected after upgrading unless every developer manually recreates their environment file.

Useful? React with 👍 / 👎.

)
: env.ALLOWED_API_ORIGINS

/**
* A utility function to create Hono apps and middlewares with the correct context type.
Expand Down
4 changes: 2 additions & 2 deletions apps/app/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# Add specific project environment variables here

# Client-side variables (PUBLIC_ prefix for Vite)
PUBLIC_BASE_URL="http://localhost:3001"
PUBLIC_BASE_URL="https://init.localhost"

# --- Auth (@init/env/auth) ---
AUTH_SECRET="dev-secret"
AUTH_TRUSTED_ORIGINS="http://localhost:3001"
AUTH_TRUSTED_ORIGINS="https://init.localhost"

# --- Auth Providers (@init/env/auth/providers) ---
GITHUB_CLIENT_ID="dev-github-client-id"
Expand Down
7 changes: 6 additions & 1 deletion apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"bump:deps": "bun update --interactive",
"clean": "git clean -xdf .cache .turbo dist node_modules",
"codegen": "paraglide-js compile --project ../../tooling/internationalization/project.inlang --outdir ./src/shared/internationalization",
"dev": "bun --bun vite dev",
"dev": "portless",
"dev:app": "bun --bun vite dev",
"preview": "bun --bun vite preview",
"start": "node .output/server/index.mjs"
},
Expand Down Expand Up @@ -56,5 +57,9 @@
"tailwindcss": "4.3.3",
"typescript": "7.0.2",
"vite": "8.1.5"
},
"portless": {
"name": "init",
"script": "dev:app"
}
}
8 changes: 6 additions & 2 deletions apps/app/src/features/auth/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ import { sendEmail } from "@init/email/client"
import PasswordReset from "@init/email/templates/password-reset"
import env from "#shared/env.ts"

const trustedOrigins = env.PORTLESS_URL
? [...new Set([...env.AUTH_TRUSTED_ORIGINS, env.PORTLESS_URL])]
: env.AUTH_TRUSTED_ORIGINS

export const auth = createAuth({
advanced: AUTH_ADVANCED_OPTIONS,
appName: AUTH_APP_NAME,
basePath: "/api/auth",
baseURL: env.PUBLIC_BASE_URL,
baseURL: env.PORTLESS_URL ?? env.PUBLIC_BASE_URL,
database: databaseAdapter(database()),
emailAndPassword: {
...AUTH_EMAIL_AND_PASSWORD_OPTIONS,
Expand All @@ -42,5 +46,5 @@ export const auth = createAuth({
enabled: true,
},
},
trustedOrigins: env.AUTH_TRUSTED_ORIGINS,
trustedOrigins,
})
3 changes: 2 additions & 1 deletion apps/app/src/shared/env.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createEnv, REACT_PUBLIC_ENV_PREFIX } from "@init/env"
import { auth, db, resend, sentry } from "@init/env/presets"
import { auth, db, portless, resend, sentry } from "@init/env/presets"
import * as z from "@init/utils/schema"
import { env, isCI } from "std-env"

Expand All @@ -14,6 +14,7 @@ export default createEnv({
auth.providers.github(),
auth.providers.google(),
db(),
portless(),
resend(),
sentry.client(),
],
Expand Down
16 changes: 10 additions & 6 deletions apps/app/src/shared/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { createUrlBuilder } from "@init/utils/url"
import { hasWindow } from "std-env"
import env from "#shared/env.ts"

const isProduction = import.meta.env.PROD
const baseUrl = hasWindow ? globalThis.location.origin : (env.PORTLESS_URL ?? env.PUBLIC_BASE_URL)

export const buildUrl = createUrlBuilder(env.PUBLIC_BASE_URL, isProduction ? "https" : "http")
export const buildApiUrl = createUrlBuilder(
env.PUBLIC_API_URL ?? `${env.PUBLIC_BASE_URL}/api`,
isProduction ? "https" : "http"
)
export const buildUrl = createUrlBuilder(baseUrl, getProtocol(baseUrl))

const apiUrl = env.PUBLIC_API_URL ?? `${baseUrl}/api`
export const buildApiUrl = createUrlBuilder(apiUrl, getProtocol(apiUrl))

function getProtocol(url: string) {
return new URL(url).protocol === "http:" ? "http" : "https"
}
2 changes: 1 addition & 1 deletion apps/app/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default defineConfig(async ({ mode }) => {
}),
],
server: {
port: 3001,
port: Number(process.env.PORT ?? 3001),
},
}
})
7 changes: 6 additions & 1 deletion apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"bump:deps": "bun update --interactive",
"clean": "git clean -xdf .cache .turbo dist node_modules",
"codegen": "paraglide-js compile --project ../../tooling/internationalization/project.inlang --outdir ./src/shared/internationalization",
"dev": "tauri dev"
"dev": "portless",
"dev:app": "tauri dev"
},
"dependencies": {
"@init/env": "workspace:*",
Expand Down Expand Up @@ -46,5 +47,9 @@
"babel-plugin-react-compiler": "1.0.0",
"typescript": "7.0.2",
"vite": "8.1.5"
},
"portless": {
"name": "desktop.init",
"script": "dev:app"
}
}
2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"build": {
"beforeBuildCommand": "bun vite build",
"beforeDevCommand": "bun vite dev",
"devUrl": "http://localhost:3003",
"devUrl": "https://desktop.init.localhost",
"frontendDist": "../dist"
},
"app": {
Expand Down
3 changes: 1 addition & 2 deletions apps/desktop/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ export default defineConfig(async ({ mode }) => {
hmr: host
? {
host,
port: 4003,
protocol: "ws",
}
: undefined,
host: host ?? false,
port: 3003,
port: Number(process.env.PORT ?? 3003),
strictPort: true,
watch: {
ignored: ["**/src-tauri/**"],
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default defineConfig({
}),
],
server: {
port: 3004,
port: Number(process.env.PORT ?? 3004),
},
vite: {
plugins: [
Expand Down
7 changes: 6 additions & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"bump:deps": "bun update --interactive",
"clean": "git clean -xdf .cache .turbo dist node_modules",
"codegen": "paraglide-js compile --project ../../tooling/internationalization/project.inlang --outdir ./src/shared/internationalization",
"dev": "astro dev",
"dev": "portless",
"dev:app": "astro dev",
"preview": "astro preview",
"typegen": "astro sync"
},
Expand All @@ -29,5 +30,9 @@
"@tooling/tsconfig": "workspace:*",
"tailwindcss": "4.3.3",
"typescript": "7.0.2"
},
"portless": {
"name": "docs.init",
"script": "dev:app"
}
}
7 changes: 6 additions & 1 deletion apps/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"bump:deps": "bun update --interactive",
"clean": "git clean -xdf .cache .turbo dist node_modules",
"codegen": "paraglide-js compile --project ../../tooling/internationalization/project.inlang --outdir ./src/shared/internationalization",
"dev": "wxt",
"dev": "portless",
"dev:app": "wxt",
"dev:firefox": "wxt -b firefox",
"postinstall": "wxt prepare",
"typegen": "wxt prepare",
Expand Down Expand Up @@ -43,5 +44,9 @@
"vite": "8.1.5",
"web-ext": "10.5.0",
"wxt": "0.21.1"
},
"portless": {
"name": "extension.init",
"script": "dev:app"
}
}
2 changes: 1 addition & 1 deletion apps/extension/wxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default defineConfig({
baseIconPath: "shared/assets/icon.svg",
},
dev: {
server: { port: 3005 },
server: { port: Number(process.env.PORT ?? 3005) },
},
imports: false,
modules: ["@wxt-dev/module-react", "@wxt-dev/auto-icons"],
Expand Down
7 changes: 6 additions & 1 deletion apps/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
"bump:deps": "bun update --interactive",
"clean": "git clean -xdf .cache .turbo .expo dist node_modules",
"codegen": "bun run scripts/codegen.ts",
"dev": "expo start --port 3002",
"dev": "portless",
"dev:android": "expo start --android",
"dev:app": "expo start --port ${PORT:-3002}",
"dev:ios": "expo start --ios",
"doctor": "expo-doctor",
"install:check": "expo install --check",
Expand Down Expand Up @@ -71,5 +72,9 @@
"babel-preset-expo": "~54.0.0",
"expo-doctor": "1.17.14",
"typescript": "7.0.2"
},
"portless": {
"name": "mobile.init",
"script": "dev:app"
}
}
2 changes: 1 addition & 1 deletion apps/web/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Add specific project environment variables here

# Client-side variables (PUBLIC_ prefix for Astro)
PUBLIC_SITE_URL="http://localhost:3006"
PUBLIC_SITE_URL="https://web.init.localhost"

# ===========OPTIONAL===========
# Optional packages that may be used in the future
Expand Down
2 changes: 1 addition & 1 deletion apps/web/astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { default: env } = await import("./src/shared/env.ts")
export default defineConfig({
output: "static",
server: {
port: 3006,
port: Number(process.env.PORT ?? 3006),
},
site: env.PUBLIC_SITE_URL ?? "https://init.now",

Expand Down
7 changes: 6 additions & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"bump:deps": "bun update --interactive",
"clean": "git clean -xdf .cache .turbo dist node_modules",
"codegen": "paraglide-js compile --project ../../tooling/internationalization/project.inlang --outdir ./src/shared/internationalization",
"dev": "astro dev",
"dev": "portless",
"dev:app": "astro dev",
"preview": "astro preview",
"typegen": "astro sync"
},
Expand Down Expand Up @@ -40,5 +41,9 @@
"@types/react-dom": "19.1.9",
"tailwindcss": "4.3.3",
"typescript": "7.0.2"
},
"portless": {
"name": "web.init",
"script": "dev:app"
}
}
Loading