You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
831 B
29 lines
831 B
import { getgid, getuid, setgid, setuid } from 'process'; |
|
|
|
import { PGID, PUID, PORT, ECODE_DROP_PRIVILEGES } from './lib/consts'; |
|
|
|
import app from './app'; |
|
import { proxyServerVncUpgrade } from './middlewares'; |
|
import { stderr, stdout } from './lib/shell'; |
|
|
|
(async () => { |
|
stdout(`Starting process with ownership ${getuid()}:${getgid()}`); |
|
|
|
const server = (await 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}`); |
|
|
|
process.exit(ECODE_DROP_PRIVILEGES); |
|
} |
|
|
|
stdout(`Listening on localhost:${PORT}.`); |
|
}); |
|
|
|
server.on('upgrade', proxyServerVncUpgrade); |
|
})();
|
|
|