Skip to content

Commit 267b63f

Browse files
committed
docs(api): details pm2 restart
1 parent bc8f218 commit 267b63f

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

apps/codever-api/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,39 @@ Based on that a GUI is generated to test the API directly from browser:
5353

5454
We currently use [pm2](https://pm2.keymetrics.io/) to start the project in production
5555

56+
### Important – restart PM2 after deploying backend changes
57+
58+
PM2 keeps the old Node.js process running until explicitly restarted.
59+
After pulling new backend code (e.g. body-parser limit changes), **always**
60+
reload or restart the PM2 process:
61+
62+
```shell
63+
pm2 reload pm2-process-cluster.json # zero-downtime reload (preferred)
64+
# or
65+
pm2 restart pm2-process-cluster.json # hard restart
66+
```
67+
68+
> **Example:** The Express body-parser is configured to accept up to **6 MB** JSON
69+
> payloads (`app.js`). If you deploy this change but forget to restart PM2,
70+
> production still runs with the old default limit (100 KB) and larger requests
71+
> (e.g. Jupyter notebook uploads) will fail with **413 Request Entity Too Large**.
72+
73+
### Nginx reverse proxy – large request bodies
74+
75+
If nginx sits in front of the API, its default `client_max_body_size` of **1 MB**
76+
can also reject large requests before they reach Node.js. Add the following to the
77+
nginx `server` or `location` block that proxies to the API:
78+
79+
```nginx
80+
client_max_body_size 6m;
81+
```
82+
83+
Then reload nginx:
84+
85+
```shell
86+
sudo nginx -t && sudo systemctl reload nginx
87+
```
88+
5689
Undo local changes if needed:
5790

5891
```

apps/codever-api/src/app.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,12 @@ setUpLogging();
7676

7777
app.use('/api/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument)); //swagger docs are not protected
7878

79-
app.use(bodyParser.json({ limit: '6mb' })); // raised from default 100kb to support Jupyter notebook uploads
80-
app.use(bodyParser.urlencoded({ extended: false }));
79+
// Raised from the default 100kb to support Jupyter notebook uploads (up to 5 MB).
80+
// IMPORTANT: if a reverse proxy (e.g. nginx) sits in front of this server, its own
81+
// body-size limit must also be raised. For nginx add to server/location block:
82+
// client_max_body_size 6m;
83+
app.use(bodyParser.json({ limit: '6mb' }));
84+
app.use(bodyParser.urlencoded({ limit: '6mb', extended: false }));
8185

8286
app.set('trust proxy', 'loopback');
8387

0 commit comments

Comments
 (0)