Skip to content

Commit

Permalink
Simplify proxy server since we need it only in production
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Sep 9, 2024
1 parent 322eadf commit d6886ce
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions proxy/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,17 @@ import { styleText } from 'node:util'

import { createProxy, DEFAULT_PROXY_CONFIG } from './index.ts'

const PORT = process.env.PORT ?? 5284

if (!process.env.PROXY_ORIGIN) {
if (!process.env.PROXY_ORIGIN || !process.env.PORT) {
process.stderr.write(
styleText('red', 'Set PROXY_ORIGIN environment variable\n')
styleText('red', 'Set PROXY_ORIGIN and PORT environment variables\n')
)
process.exit(0)
}

let proxy = createServer(
createProxy({ ...DEFAULT_PROXY_CONFIG, allowsFrom: process.env.PROXY_ORIGIN })
)

proxy.listen(PORT, () => {
if (process.env.NODE_ENV !== 'production') {
process.stdout.write(
styleText('green', `Proxy server running on port ${PORT}`) + '\n'
)
}
})
proxy.listen(process.env.PORT)

process.on('SIGINT', () => {
proxy.close()
Expand Down

0 comments on commit d6886ce

Please sign in to comment.