File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed
Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ import { type } from "arktype";
55import credentialService from "./service/credentials.ts" ;
66import { serve , type ServerType } from "@hono/node-server" ;
77
8+ const DEFAULT_PORT = 16281 ;
9+
810function createApp ( ) {
911 const app = new Hono ( ) ;
1012
@@ -63,12 +65,24 @@ function createApp() {
6365 return app ;
6466}
6567
68+ function getPort ( ) : number {
69+ const portFromEnv = process . env . CREDENTIAL_BRIDGE_PORT ;
70+ if ( portFromEnv ) {
71+ const parsedPortFromEnv = parseInt ( portFromEnv ) ;
72+ // validate the port to be a valid port number
73+ if ( isNaN ( parsedPortFromEnv ) || parsedPortFromEnv < 1 || parsedPortFromEnv > 65535 ) {
74+ return DEFAULT_PORT ;
75+ }
76+ return parsedPortFromEnv ;
77+ }
78+ return DEFAULT_PORT ;
79+ }
80+
6681export function startServer ( ) : ServerType | undefined {
6782 try {
6883 const app = createApp ( ) ;
69- const port = 16281 ;
7084 const hostname = "0.0.0.0" ;
71-
85+ const port = getPort ( ) ;
7286 const server = serve ( {
7387 ...app ,
7488 port,
You can’t perform that action at this time.
0 commit comments