fix: remove dependency from tenant router
This commit is contained in:
@@ -12,7 +12,7 @@ The Worker forwards each request to one of two Render services based on path:
|
|||||||
|
|
||||||
| Host / path | Upstream |
|
| Host / path | Upstream |
|
||||||
| ------------- | ------------------------------------------------------------ |
|
| ------------- | ------------------------------------------------------------ |
|
||||||
| `embed.*` | R2 `assets` bucket — `/{widget}` maps to internal keys (`@cio/utils/constants/embeds`) |
|
| `embed.*` | R2 `assets` bucket — `/{widget}` maps to internal keys (`src/embed-assets.ts`) |
|
||||||
| `/proxy/*` | API service (`/proxy` prefix stripped, rest forwarded as-is) |
|
| `/proxy/*` | API service (`/proxy` prefix stripped, rest forwarded as-is) |
|
||||||
| anything else | Dashboard service |
|
| anything else | Dashboard service |
|
||||||
|
|
||||||
@@ -29,8 +29,6 @@ It preserves the original host as `X-Forwarded-Host` so:
|
|||||||
|
|
||||||
## Deploy
|
## Deploy
|
||||||
|
|
||||||
`deploy` runs `predeploy`, which builds `@cio/utils` first (Wrangler resolves `@cio/utils/constants/*` from `dist/`).
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pnpm --filter @cio/tenant-router deploy
|
pnpm --filter @cio/tenant-router deploy
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -5,17 +5,11 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "wrangler dev",
|
"dev": "wrangler dev",
|
||||||
"predev": "pnpm --filter @cio/utils build",
|
|
||||||
"deploy": "wrangler deploy",
|
"deploy": "wrangler deploy",
|
||||||
"predeploy": "pnpm --filter @cio/utils build",
|
|
||||||
"tail": "wrangler tail",
|
"tail": "wrangler tail",
|
||||||
"typecheck": "tsc --noEmit",
|
"typecheck": "tsc --noEmit",
|
||||||
"pretypecheck": "pnpm --filter @cio/utils build",
|
|
||||||
"format": "prettier --write ."
|
"format": "prettier --write ."
|
||||||
},
|
},
|
||||||
"dependencies": {
|
|
||||||
"@cio/utils": "workspace:*"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@cloudflare/workers-types": "^4.20250109.0",
|
"@cloudflare/workers-types": "^4.20250109.0",
|
||||||
"typescript": "^5.5.2",
|
"typescript": "^5.5.2",
|
||||||
|
|||||||
@@ -1,4 +1,20 @@
|
|||||||
import { EMBED_WIDGET_ROUTES } from '@cio/utils/constants/embeds';
|
type EmbedWidgetRoute = {
|
||||||
|
scriptKey: string;
|
||||||
|
pageKey?: string;
|
||||||
|
pageQueryParam?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Public path segment → R2 object keys under the `assets` bucket. */
|
||||||
|
const EMBED_WIDGET_ROUTES: Record<string, EmbedWidgetRoute> = {
|
||||||
|
'course-widget': {
|
||||||
|
scriptKey: 'embeds/course-widget/course-widget.js',
|
||||||
|
pageKey: 'embeds/course-widget/embed.html',
|
||||||
|
pageQueryParam: 'key'
|
||||||
|
},
|
||||||
|
'question-type-picker': {
|
||||||
|
scriptKey: 'embeds/question-type-picker/question-type-picker.js'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const EMBED_CONTENT_TYPES: Record<string, string> = {
|
const EMBED_CONTENT_TYPES: Record<string, string> = {
|
||||||
html: 'text/html',
|
html: 'text/html',
|
||||||
@@ -43,7 +59,7 @@ function cacheControlForObjectKey(objectKey: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function resolvePublicWidgetKey(pathname: string, searchParams: URLSearchParams): string | null {
|
function resolvePublicWidgetKey(pathname: string, searchParams: URLSearchParams): string | null {
|
||||||
const route = EMBED_WIDGET_ROUTES[pathname as keyof typeof EMBED_WIDGET_ROUTES];
|
const route = EMBED_WIDGET_ROUTES[pathname];
|
||||||
if (!route) {
|
if (!route) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,31 +2,8 @@ export const EMBED_PUBLIC_HOST = 'embed.classroomio.com';
|
|||||||
|
|
||||||
export const EMBED_PUBLIC_BASE_URL = `https://${EMBED_PUBLIC_HOST}`;
|
export const EMBED_PUBLIC_BASE_URL = `https://${EMBED_PUBLIC_HOST}`;
|
||||||
|
|
||||||
export type EmbedWidgetRoute = {
|
/** Widget names exposed at `https://embed.classroomio.com/{name}`. */
|
||||||
/** R2 object key for the ES module bootstrap. */
|
export type EmbedWidgetName = 'course-widget' | 'question-type-picker';
|
||||||
scriptKey: string;
|
|
||||||
/** R2 object key for the hosted iframe page, when supported. */
|
|
||||||
pageKey?: string;
|
|
||||||
/** Query param that selects the hosted page instead of the script. */
|
|
||||||
pageQueryParam?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Public path segment → internal R2 keys under the `assets` bucket.
|
|
||||||
* Customers only copy `https://embed.classroomio.com/{widgetName}`.
|
|
||||||
*/
|
|
||||||
export const EMBED_WIDGET_ROUTES = {
|
|
||||||
'course-widget': {
|
|
||||||
scriptKey: 'embeds/course-widget/course-widget.js',
|
|
||||||
pageKey: 'embeds/course-widget/embed.html',
|
|
||||||
pageQueryParam: 'key'
|
|
||||||
},
|
|
||||||
'question-type-picker': {
|
|
||||||
scriptKey: 'embeds/question-type-picker/question-type-picker.js'
|
|
||||||
}
|
|
||||||
} as const satisfies Record<string, EmbedWidgetRoute>;
|
|
||||||
|
|
||||||
export type EmbedWidgetName = keyof typeof EMBED_WIDGET_ROUTES;
|
|
||||||
|
|
||||||
export function getEmbedBaseUrl(override?: string): string {
|
export function getEmbedBaseUrl(override?: string): string {
|
||||||
return (override ?? EMBED_PUBLIC_BASE_URL).replace(/\/$/, '');
|
return (override ?? EMBED_PUBLIC_BASE_URL).replace(/\/$/, '');
|
||||||
|
|||||||
Generated
-4
@@ -782,10 +782,6 @@ importers:
|
|||||||
version: 4.2.1
|
version: 4.2.1
|
||||||
|
|
||||||
apps/tenant-router:
|
apps/tenant-router:
|
||||||
dependencies:
|
|
||||||
'@cio/utils':
|
|
||||||
specifier: workspace:*
|
|
||||||
version: link:../../packages/utils
|
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@cloudflare/workers-types':
|
'@cloudflare/workers-types':
|
||||||
specifier: ^4.20250109.0
|
specifier: ^4.20250109.0
|
||||||
|
|||||||
Reference in New Issue
Block a user