diff --git a/CHANGELOG.md b/CHANGELOG.md index fecda23..b8ec03a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.1.4 + +- Added support for Windows + ## 0.1.3 - Fix missing README in published package @@ -14,7 +18,8 @@ - Non-HTML assets can be served from CDN edge network via convex-fs - New `cdnBaseUrl` option on `registerStaticRoutes` - Schema: `storageId` now optional, new `blobId` field for CDN assets -- `gcOldAssets` returns `{ deleted, blobIds }` (breaking change from number return) +- `gcOldAssets` returns `{ deleted, blobIds }` (breaking change from number + return) ## 0.1.2-alpha.1 diff --git a/dist/cli/init.d.ts b/dist/cli/init.d.ts index 37d60c9..06ae4fd 100644 --- a/dist/cli/init.d.ts +++ b/dist/cli/init.d.ts @@ -5,5 +5,5 @@ * Usage: * npx @convex-dev/static-hosting init */ -declare const instructions = "\n# Convex Static Hosting - Integration Instructions\n\nYou are integrating the @convex-dev/static-hosting component into a Convex app.\nThis component enables hosting static files (React/Vite apps) directly on Convex.\n\n## What This Component Does\n\n- Stores static files in Convex storage\n- Serves files via HTTP actions with proper MIME types\n- Supports SPA routing (fallback to index.html)\n- Smart caching: hashed assets cached forever, HTML revalidates\n- ETag support for efficient cache revalidation\n- Live reload notifications when new deployments happen\n\n## Files to Create/Modify\n\n### 1. convex/convex.config.ts (create or modify)\n\n```typescript\nimport { defineApp } from \"convex/server\";\nimport selfHosting from \"@convex-dev/static-hosting/convex.config\";\n\nconst app = defineApp();\napp.use(selfHosting);\n\nexport default app;\n```\n\n### 2. convex/staticHosting.ts (create)\n\n```typescript\nimport { components } from \"./_generated/api\";\nimport {\n exposeUploadApi,\n exposeDeploymentQuery,\n} from \"@convex-dev/static-hosting\";\n\n// Internal functions for secure uploads (only callable via CLI)\nexport const { generateUploadUrl, generateUploadUrls, recordAsset, recordAssets, gcOldAssets, listAssets } =\n exposeUploadApi(components.selfHosting);\n\n// Public query for live reload notifications\nexport const { getCurrentDeployment } =\n exposeDeploymentQuery(components.selfHosting);\n```\n\n### 3. convex/http.ts (create or modify)\n\n```typescript\nimport { httpRouter } from \"convex/server\";\nimport { registerStaticRoutes } from \"@convex-dev/static-hosting\";\nimport { components } from \"./_generated/api\";\n\nconst http = httpRouter();\n\n// Option A: Serve at root (if no other HTTP routes)\nregisterStaticRoutes(http, components.selfHosting);\n\n// Option B: Serve at /app/ prefix (recommended if you have API routes)\n// registerStaticRoutes(http, components.selfHosting, {\n// pathPrefix: \"/app\",\n// });\n\n// Add other HTTP routes here if needed\n// http.route({ path: \"/api/webhook\", method: \"POST\", handler: ... });\n\nexport default http;\n```\n\n### 4. package.json scripts (add)\n\n```json\n{\n \"scripts\": {\n \"build\": \"vite build\",\n \"deploy:static\": \"npx @convex-dev/static-hosting upload --build --prod\"\n }\n}\n```\n\nIMPORTANT: Use `--build` flag instead of running `npm run build` separately.\nThe `--build` flag ensures `VITE_CONVEX_URL` is set correctly for the target\nenvironment (production or dev). Running build separately uses .env.local which\nhas the dev URL.\n\n### 5. src/App.tsx (optional: add live reload banner)\n\n```typescript\nimport { UpdateBanner } from \"@convex-dev/static-hosting/react\";\nimport { api } from \"../convex/_generated/api\";\n\nfunction App() {\n return (\n
\n {/* Shows banner when new deployment is available */}\n \n \n {/* Rest of your app */}\n
\n );\n}\n```\n\nOr use the hook for custom UI:\n```typescript\nimport { useDeploymentUpdates } from \"@convex-dev/static-hosting/react\";\nimport { api } from \"../convex/_generated/api\";\n\nfunction App() {\n const { updateAvailable, reload, dismiss } = useDeploymentUpdates(\n api.staticHosting.getCurrentDeployment\n );\n \n // Custom update notification UI\n}\n```\n\n## Deployment\n\n```bash\n# Login to Convex (first time)\nnpx convex login\n\n# Deploy Convex backend to production FIRST\nnpx convex deploy\n\n# Deploy static files to production\nnpm run deploy:static\n\n# Your app is now live at:\n# https://your-deployment.convex.site\n# (or https://your-deployment.convex.site/app/ if using path prefix)\n```\n\nFor development/testing:\n```bash\n# Push to dev environment\nnpx convex dev --once\n\n# Deploy static files to dev (omit --prod)\nnpx @convex-dev/static-hosting upload --build\n```\n\n## CLI Reference\n\n```bash\nnpx @convex-dev/static-hosting upload [options]\n\nOptions:\n -d, --dist Path to dist directory (default: ./dist)\n -c, --component Convex component name (default: staticHosting)\n --prod Deploy to production Convex deployment\n --dev Deploy to dev deployment (default)\n -b, --build Run 'npm run build' with correct VITE_CONVEX_URL\n -h, --help Show help\n```\n\n## Important Notes\n\n1. The upload functions are INTERNAL - they can only be called via `npx convex run`, not from the public internet\n2. Static files are stored in the app's storage (not the component's) for proper isolation\n3. Hashed assets (e.g., main-abc123.js) get immutable caching; HTML files always revalidate\n4. The component supports SPA routing - routes without file extensions serve index.html\n5. Always use `--build` flag to ensure VITE_CONVEX_URL is set correctly for the target environment\n6. Deploy Convex backend (`npx convex deploy`) BEFORE deploying static files to production\n"; +declare const instructions = "\n# Convex Static Hosting - Integration Instructions\n\nYou are integrating the @convex-dev/static-hosting component into a Convex app.\nThis component enables hosting static files (React/Vite apps) directly on Convex.\n\n## What This Component Does\n\n- Stores static files in Convex storage\n- Serves files via HTTP actions with proper MIME types\n- Supports SPA routing (fallback to index.html)\n- Smart caching: hashed assets cached forever, HTML revalidates\n- ETag support for efficient cache revalidation\n- Live reload notifications when new deployments happen\n\n## Files to Create/Modify\n\n### 1. convex/convex.config.ts (create or modify)\n\n```typescript\nimport { defineApp } from \"convex/server\";\nimport selfHosting from \"@convex-dev/static-hosting/convex.config\";\n\nconst app = defineApp();\napp.use(selfHosting);\n\nexport default app;\n```\n\n### 2. convex/staticHosting.ts (create)\n\n```typescript\nimport { components } from \"./_generated/api\";\nimport {\n exposeUploadApi,\n exposeDeploymentQuery,\n} from \"@convex-dev/static-hosting\";\n\n// Internal functions for secure uploads (only callable via CLI)\nexport const { generateUploadUrl, generateUploadUrls, recordAsset, recordAssets, gcOldAssets, listAssets } =\n exposeUploadApi(components.selfHosting);\n\n// Public query for live reload notifications\nexport const { getCurrentDeployment } =\n exposeDeploymentQuery(components.selfHosting);\n```\n\n### 3. convex/http.ts (create or modify)\n\n```typescript\nimport { httpRouter } from \"convex/server\";\nimport { registerStaticRoutes } from \"@convex-dev/static-hosting\";\nimport { components } from \"./_generated/api\";\n\nconst http = httpRouter();\n\n// Option A: Serve at root (if no other HTTP routes)\nregisterStaticRoutes(http, components.selfHosting);\n\n// Option B: Serve at /app/ prefix (recommended if you have API routes)\n// registerStaticRoutes(http, components.selfHosting, {\n// pathPrefix: \"/app\",\n// });\n\n// Add other HTTP routes here if needed\n// http.route({ path: \"/api/webhook\", method: \"POST\", handler: ... });\n\nexport default http;\n```\n\n### 4. package.json scripts (add)\n\n```json\n{\n \"scripts\": {\n \"build\": \"vite build\",\n \"deploy:static\": \"npx @convex-dev/static-hosting upload --build --prod\"\n }\n}\n```\n\nIMPORTANT: Use `--build` flag instead of running `npm run build` separately.\nThe `--build` flag ensures `VITE_CONVEX_URL` is set correctly for the target\nenvironment (production or dev). Running build separately uses .env.local which\nhas the dev URL.\n\n### 5. src/App.tsx (optional: add live reload banner)\n\n```typescript\nimport { UpdateBanner } from \"@convex-dev/static-hosting/react\";\nimport { api } from \"../convex/_generated/api\";\n\nfunction App() {\n return (\n
\n {/* Shows banner when new deployment is available */}\n \n \n {/* Rest of your app */}\n
\n );\n}\n```\n\nOr use the hook for custom UI:\n```typescript\nimport { useDeploymentUpdates } from \"@convex-dev/static-hosting/react\";\nimport { api } from \"../convex/_generated/api\";\n\nfunction App() {\n const { updateAvailable, reload, dismiss } = useDeploymentUpdates(\n api.staticHosting.getCurrentDeployment\n );\n \n // Custom update notification UI\n}\n```\n\n## Deployment\n\n```bash\n# Login to Convex (first time)\nnpx convex login\n\n# Deploy Convex backend to production FIRST\nnpx convex deploy\n\n# Deploy static files to production\nnpm run deploy:static\n\n# Your app is now live at:\n# https://your-deployment.convex.site\n# (or https://your-deployment.convex.site/app/ if using path prefix)\n```\n\nFor development/testing:\n```bash\n# Push to dev environment\nnpx convex dev --once\n\n# Deploy static files to dev (omit --prod)\nnpx @convex-dev/static-hosting upload --build\n```\n\n## CLI Reference\n\n```bash\nnpx @convex-dev/static-hosting upload [options]\n\nOptions:\n -d, --dist Path to dist directory (default: ./dist)\n -c, --component Module name where upload API is exposed \u2014 i.e. convex/.ts (default: staticHosting)\n --prod Deploy to production Convex deployment\n --dev Deploy to dev deployment (default)\n -b, --build Run 'npm run build' with correct VITE_CONVEX_URL\n -h, --help Show help\n```\n\n## Important Notes\n\n1. The upload functions are INTERNAL - they can only be called via `npx convex run`, not from the public internet\n2. Static files are stored in the app's storage (not the component's) for proper isolation\n3. Hashed assets (e.g., main-abc123.js) get immutable caching; HTML files always revalidate\n4. The component supports SPA routing - routes without file extensions serve index.html\n5. Always use `--build` flag to ensure VITE_CONVEX_URL is set correctly for the target environment\n6. Deploy Convex backend (`npx convex deploy`) BEFORE deploying static files to production\n"; //# sourceMappingURL=init.d.ts.map \ No newline at end of file diff --git a/dist/cli/init.d.ts.map b/dist/cli/init.d.ts.map index 60ec5a3..0104f94 100644 --- a/dist/cli/init.d.ts.map +++ b/dist/cli/init.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/cli/init.ts"],"names":[],"mappings":";AACA;;;;;GAKG;AAEH,QAAA,MAAM,YAAY,q/JA0KjB,CAAC"} \ No newline at end of file +{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/cli/init.ts"],"names":[],"mappings":";AACA;;;;;GAKG;AAEH,QAAA,MAAM,YAAY,siKA0KjB,CAAC"} \ No newline at end of file diff --git a/dist/cli/init.js b/dist/cli/init.js index e827ada..b4a837e 100644 --- a/dist/cli/init.js +++ b/dist/cli/init.js @@ -161,7 +161,7 @@ npx @convex-dev/static-hosting upload [options] Options: -d, --dist Path to dist directory (default: ./dist) - -c, --component Convex component name (default: staticHosting) + -c, --component Module name where upload API is exposed — i.e. convex/.ts (default: staticHosting) --prod Deploy to production Convex deployment --dev Deploy to dev deployment (default) -b, --build Run 'npm run build' with correct VITE_CONVEX_URL diff --git a/dist/cli/upload.d.ts b/dist/cli/upload.d.ts index 8204586..501e628 100644 --- a/dist/cli/upload.d.ts +++ b/dist/cli/upload.d.ts @@ -7,7 +7,7 @@ * * Options: * --dist Path to dist directory (default: ./dist) - * --component Convex component with upload functions (default: staticHosting) + * --component Module name where upload API is exposed — i.e. convex/.ts (default: staticHosting) * --prod Deploy to production deployment * --help Show help */ diff --git a/dist/component/lib.d.ts b/dist/component/lib.d.ts index 3ab1d45..42c7fa5 100644 --- a/dist/component/lib.d.ts +++ b/dist/component/lib.d.ts @@ -7,8 +7,8 @@ export declare const getByPath: import("convex/server").RegisteredQuery<"public" }, Promise<{ _id: import("convex/values").GenericId<"staticAssets">; _creationTime: number; - storageId?: import("convex/values").GenericId<"_storage"> | undefined; blobId?: string | undefined; + storageId?: import("convex/values").GenericId<"_storage"> | undefined; path: string; contentType: string; deploymentId: string; @@ -27,8 +27,8 @@ export declare const generateUploadUrl: import("convex/server").RegisteredMutati * The caller is responsible for deleting the returned storageId from app storage. */ export declare const recordAsset: import("convex/server").RegisteredMutation<"public", { - storageId?: import("convex/values").GenericId<"_storage"> | undefined; blobId?: string | undefined; + storageId?: import("convex/values").GenericId<"_storage"> | undefined; path: string; contentType: string; deploymentId: string; @@ -54,8 +54,8 @@ export declare const listAssets: import("convex/server").RegisteredQuery<"public }, Promise<{ _id: import("convex/values").GenericId<"staticAssets">; _creationTime: number; - storageId?: import("convex/values").GenericId<"_storage"> | undefined; blobId?: string | undefined; + storageId?: import("convex/values").GenericId<"_storage"> | undefined; path: string; contentType: string; deploymentId: string; diff --git a/package-lock.json b/package-lock.json index 1da32e0..ea94710 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@convex-dev/static-hosting", - "version": "0.1.3", + "version": "0.1.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@convex-dev/static-hosting", - "version": "0.1.3", + "version": "0.1.4", "hasInstallScript": true, "license": "Apache-2.0", "bin": { diff --git a/package.json b/package.json index b6abadb..071faa3 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "bugs": { "url": "https://github.com/get-convex/static-hosting/issues" }, - "version": "0.1.3", + "version": "0.1.4", "license": "Apache-2.0", "keywords": [ "convex",