diff --git a/server.js b/server.js index 7847c6a..79a33f3 100644 --- a/server.js +++ b/server.js @@ -481,16 +481,31 @@ app.get('/callback', (req, res) => { }); async function startServer() { - await initJwks(); - await initOidc(); - - app.listen(PORT, '0.0.0.0', () => { - console.log(`\n================================================================`); - console.log(`[서버 기동] Headless 로그인 데모 서버가 실행 중입니다.`); - console.log(`- 접속 주소: http://172.16.9.208:${PORT}`); - console.log(`- 로컬 주소: http://localhost:${PORT}`); - console.log(`================================================================\n`); - }); + try { + await initJwks(); + await initOidc(); + + const server = app.listen(PORT, '0.0.0.0', () => { + console.log(`\n================================================================`); + console.log(`[서버 기동] Headless 로그인 데모 서버가 실행 중입니다.`); + console.log(`- 접속 주소: http://172.16.9.208:${PORT}`); + console.log(`- 로컬 주소: http://localhost:${PORT}`); + console.log(`================================================================\n`); + }); + + server.on('error', (err) => { + if (err.code === 'EADDRINUSE') { + console.error(`\n[오류] ${PORT}번 포트가 이미 사용 중입니다. 다른 포트를 사용하거나 해당 프로세스를 종료해주세요.`); + } else { + console.error(`\n[오류] 서버 실행 중 에러 발생:`, err.message); + } + process.exit(1); + }); + + } catch (err) { + console.error('\n[오류] 서버 초기화 실패:', err.message); + process.exit(1); + } } startServer();