Skip to content

Commit

Permalink
chore: create different proxy setup for parrot
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasBuchfink committed Jun 24, 2024
1 parent f4646f6 commit b12125b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
3 changes: 3 additions & 0 deletions inlang/source-code/telemetry-proxy-parrot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @inlang/telemetry-proxy-parrot

The server that redirects telemetry requests to the correct server.
23 changes: 23 additions & 0 deletions inlang/source-code/telemetry-proxy-parrot/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@inlang/telemetry-proxy-parrot",
"type": "module",
"private": true,
"scripts": {
"dev": "node --loader tsx ./src/main.ts",
"production": "NODE_ENV=production tsx ./src/main.ts",
"lint": "eslint ./src --fix",
"format": "prettier ./src --write",
"clean": "rm -rf ./dist ./node_modules"
},
"dependencies": {
"express": "^4.18.2",
"http-proxy-middleware": "^2.0.6",
"tsx": "3.12.7"
},
"devDependencies": {
"@types/express": "^4.17.17",
"typescript": "^5.5.2"
},
"license": "Apache-2.0",
"version": "0.0.1"
}
30 changes: 30 additions & 0 deletions inlang/source-code/telemetry-proxy-parrot/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import express from "express"
import { createProxyMiddleware } from "http-proxy-middleware"

// --------------- SETUP -----------------

export const isProduction = process.env.NODE_ENV === "production"

const app = express()

// ----------------- ROUTES ----------------------

app.use(
"*",
createProxyMiddleware({
target: "https://eu.posthog.com",
changeOrigin: true,
onProxyReq: (req) => {
req.path
},
onProxyRes: (proxyRes) => {
proxyRes.headers["Access-Control-Allow-Origin"] = "null"
},
})
)

// ----------------- START SERVER -----------------

const port = process.env.PORT ?? 4006
app.listen(port)
console.info(`Server running at http://localhost:${port}/`)
11 changes: 11 additions & 0 deletions inlang/source-code/telemetry-proxy-parrot/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../tsconfig.base.json",
"include": ["src/*.ts"],
"compilerOptions": {
// DOM because of fetch. TODO: extract fetch from this package and
// let fetch be provided by the environment.
"lib": ["ESNext", "DOM"],
"types": [],
"rootDir": "./src"
}
}

0 comments on commit b12125b

Please sign in to comment.