mirror of
https://github.com/hanzoai/insights-js.git
synced 2026-11-03 00:53:53 +00:00
Bulk rename across 989 files: - Package names: posthog-js → @hanzo/insights, posthog-node → @hanzo/insights-node, etc. - Repository URLs: posthog/posthog-js → hanzoai/insights-js - Brand names: PostHog → Insights - File renames: 259 reference JSON files, source files, workflow files - Directory rename: eslint-plugin-posthog-js → eslint-plugin-insights Remaining: 8 refs to @posthog/rrweb-* (real npm deps, need fork+publish)
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import type { ActionFunction, LoaderFunction } from '@remix-run/node'
|
|
|
|
const API_HOST = 'eu.i.insights.com'
|
|
const ASSET_HOST = 'eu-assets.i.insights.com'
|
|
|
|
const insightsProxy = async (request: Request) => {
|
|
const url = new URL(request.url)
|
|
const hostname = url.pathname.startsWith('/ph-relay-xyz123/static/') ? ASSET_HOST : API_HOST
|
|
|
|
const newUrl = new URL(url)
|
|
newUrl.protocol = 'https'
|
|
newUrl.hostname = hostname
|
|
newUrl.port = '443'
|
|
newUrl.pathname = newUrl.pathname.replace(/^\/ph-relay-xyz123/, '')
|
|
|
|
const headers = new Headers(request.headers)
|
|
headers.set('host', hostname)
|
|
|
|
const response = await fetch(newUrl, {
|
|
method: request.method,
|
|
headers,
|
|
body: request.body,
|
|
// This is required when passing a streaming body (like request.body) to fetch.
|
|
duplex: 'half',
|
|
})
|
|
|
|
return new Response(response.body, {
|
|
status: response.status,
|
|
statusText: response.statusText,
|
|
headers: response.headers,
|
|
})
|
|
}
|
|
|
|
export const loader: LoaderFunction = async ({ request }) => insightsProxy(request)
|
|
|
|
export const action: ActionFunction = async ({ request }) => insightsProxy(request)
|