feat: fallback to PORT env var when listening

Signed-off-by: Ricardo Arturo Cabral Mejía <me@ricardocabral.io>
This commit is contained in:
Ricardo Arturo Cabral Mejía
2022-12-28 20:04:14 -05:00
parent 77dcc8abdc
commit 1b5008567b
3 changed files with 8 additions and 5 deletions

View File

@@ -12,7 +12,7 @@ RUN npm run build
FROM node:18-alpine3.16 FROM node:18-alpine3.16
LABEL org.opencontainers.image.title="Nostr Typescript Relay" LABEL org.opencontainers.image.title="Nostream"
LABEL org.opencontainers.image.source=https://github.com/Cameri/nostream LABEL org.opencontainers.image.source=https://github.com/Cameri/nostream
LABEL org.opencontainers.image.description="nostream" LABEL org.opencontainers.image.description="nostream"
LABEL org.opencontainers.image.authors="Ricardo Arturo Cabral Mejía" LABEL org.opencontainers.image.authors="Ricardo Arturo Cabral Mejía"

View File

@@ -19,9 +19,8 @@ export class AppWorker implements IRunnable {
} }
public run(): void { public run(): void {
const port = Number(process.env.RELAY_PORT) || 8008 const port = process.env.RELAY_PORT ?? process.env.PORT ?? 8008
this.adapter.listen(typeof port === 'number' ? port : Number(port))
this.adapter.listen(port)
} }
private onMessage(message: { eventName: string, event: unknown }): void { private onMessage(message: { eventName: string, event: unknown }): void {

6
src/cache/client.ts vendored
View File

@@ -1,5 +1,9 @@
import { createClient, RedisClientOptions } from 'redis' import { createClient, RedisClientOptions } from 'redis'
import { CacheClient } from '../@types/cache' import { CacheClient } from '../@types/cache'
import { createLogger } from '../factories/logger-factory'
const debug = createLogger('cache-client')
export const getCacheConfig = (): RedisClientOptions => ({ export const getCacheConfig = (): RedisClientOptions => ({
url: `redis://${process.env.REDIS_USER}:${process.env.REDIS_PASSWORD}@${process.env.REDIS_HOST}:${process.env.REDIS_PORT}`, url: `redis://${process.env.REDIS_USER}:${process.env.REDIS_PASSWORD}@${process.env.REDIS_HOST}:${process.env.REDIS_PORT}`,
@@ -11,7 +15,7 @@ let instance: CacheClient | undefined = undefined
export const getCacheClient = (): CacheClient => { export const getCacheClient = (): CacheClient => {
if (!instance) { if (!instance) {
const config = getCacheConfig() const config = getCacheConfig()
debug('config: %o', config)
instance = createClient(config) instance = createClient(config)
} }