| 48 | } |
| 49 | |
| 50 | async function run() { |
| 51 | const api = start('api', process.execPath, ['./server/index.mjs']) |
| 52 | const web = start('web', viteCommand, [], { |
| 53 | VITE_PAGINATION_API_PORT: String(API_PORT), |
| 54 | }) |
| 55 | |
| 56 | const shutdown = async () => { |
| 57 | await Promise.all([stop(web), stop(api)]) |
| 58 | } |
| 59 | |
| 60 | process.on('SIGINT', shutdown) |
| 61 | process.on('SIGTERM', shutdown) |
| 62 | |
| 63 | const [winner] = await Promise.race([ |
| 64 | once(api, 'exit').then(([code]) => ({ name: 'api', code })), |
| 65 | once(web, 'exit').then(([code]) => ({ name: 'web', code })), |
| 66 | ]) |
| 67 | |
| 68 | await shutdown() |
| 69 | |
| 70 | if (winner.code !== 0 && winner.code !== null) { |
| 71 | process.exitCode = winner.code |
| 72 | } else { |
| 73 | process.exitCode = 1 |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | run().catch((error) => { |
| 78 | console.error(error) |