diff --git a/Dockerfile b/Dockerfile index b5f4f49..2a3dc09 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,8 +10,6 @@ WORKDIR /app COPY app/ ./ -RUN npm install pm2 -g - RUN chown -R node:node /app USER node @@ -29,4 +27,4 @@ RUN npx tsc --noCheck HEALTHCHECK --interval=30s --start-period=10s --timeout=5s CMD wget -q --spider http://localhost:3000/share/healthcheck || exit 1 -CMD ["pm2-runtime", "dist/index.js" ] +CMD ["node", "dist/index.js" ] diff --git a/README.md b/README.md index b24ec8f..3faa297 100644 --- a/README.md +++ b/README.md @@ -184,6 +184,17 @@ For example, to disable the download button for images, you would edit the `ligh } ``` +### Customising your error response pages + +You can customise the responses that IPP sends for invalid requests. For example you could: + +- Drop the connection entirely (no response). +- Redirect to a new website. +- Send a different status code. +- And so on... + +See [Custom responses](docs/custom-responses.md) for more details. + ## Troubleshooting If you're using Cloudflare and having issues with videos not playing well, make sure your `/share/video/` paths are set to bypass cache. diff --git a/app/package.json b/app/package.json index 018132e..a2541eb 100644 --- a/app/package.json +++ b/app/package.json @@ -4,7 +4,7 @@ "scripts": { "dev": "ts-node src/index.ts", "build": "npx tsc", - "test": "podman build --build-arg PACKAGE_VERSION=$(npm pkg get version | xargs) --format docker -t immich-proxy-test .. && podman run --init -it -p=3000:3000 --env-file .env immich-proxy-test", + "test": "podman build --build-arg PACKAGE_VERSION=$(npm pkg get version | xargs) --format docker -t immich-proxy-test .. && podman run --init -it -p=3000:3000 --env-file .env --restart=always immich-proxy-test", "start": "node dist/index.js" }, "author": "Alan Grainger", diff --git a/app/src/index.ts b/app/src/index.ts index e326daf..02dbd02 100644 --- a/app/src/index.ts +++ b/app/src/index.ts @@ -66,6 +66,7 @@ const decodeCookie = (req: Request, _res: Response, next: NextFunction) => { app.get(/^(|\/share)\/healthcheck$/, async (_req, res) => { if (await immich.accessible()) { res.send('ok') + throw new Error('asdf') } else { res.status(503).send() } @@ -164,8 +165,26 @@ app.get('*', (req, res) => { respondToInvalidRequest(res, 404) }) +// Send the correct process error code for any uncaught exceptions +// so that Docker can gracefully restart the container +process.on('uncaughtException', (err) => { + console.error('There was an uncaught error', err) + server.close() + process.exit(1) +}) +process.on('unhandledRejection', (reason, promise) => { + console.error('Unhandled Rejection at:', promise, 'reason:', reason) + server.close() + process.exit(1) +}) +process.on('SIGTERM', () => { + console.log('Received SIGTERM. Gracefully shutting down...') + server.close() + process.exit(0) +}) + // Start the ExpressJS server const port = process.env.IPP_PORT || 3000 -app.listen(port, () => { +const server = app.listen(port, () => { console.log(dayjs().format() + ' Server started on port ' + port) })