parent
fc73f4ec15
commit
67b292dd95
4 changed files with 25 additions and 6 deletions
@ -1,7 +1,24 @@ |
||||
import { getgid, getuid, setgid, setuid } from 'process'; |
||||
|
||||
import { PGID, PUID, PORT } from './lib/consts'; |
||||
|
||||
import app from './app'; |
||||
import { stderr, stdout } from './lib/shell'; |
||||
|
||||
stdout(`Starting process with ownership ${getuid()}:${getgid()}`); |
||||
|
||||
app.listen(PORT, () => { |
||||
try { |
||||
// Group must be set before user to avoid permission error.
|
||||
setgid(PGID); |
||||
setuid(PUID); |
||||
|
||||
stdout(`Process ownership changed to ${getuid()}:${getgid()}.`); |
||||
} catch (error) { |
||||
stderr(`Failed to change process ownership; CAUSE: ${error}`); |
||||
|
||||
import SERVER_PORT from './lib/consts/SERVER_PORT'; |
||||
process.exit(1); |
||||
} |
||||
|
||||
app.listen(SERVER_PORT, () => { |
||||
console.log(`Listening on localhost:${SERVER_PORT}.`); |
||||
stdout(`Listening on localhost:${PORT}.`); |
||||
}); |
||||
|
@ -0,0 +1,2 @@ |
||||
export const PUID = process.env.PUID ?? 'striker-ui-api'; |
||||
export const PGID = process.env.PGID ?? PUID; |
@ -1,3 +1 @@ |
||||
const SERVER_PORT = process.env.SERVER_PORT ?? 8080; |
||||
|
||||
export default SERVER_PORT; |
||||
export const PORT = process.env.PORT ?? 8080; |
||||
|
@ -0,0 +1,2 @@ |
||||
export * from './PROCESS_OWNER'; |
||||
export * from './SERVER_PORT'; |
Loading…
Reference in new issue