nibula 1.6.0 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eleventy.js +82 -81
- package/CHANGELOG.md +395 -377
- package/LICENSE +169 -169
- package/NOTICE +4 -4
- package/README.md +110 -110
- package/bin/create.js +540 -505
- package/bin/delegate.js +58 -57
- package/bin/nibula.js +302 -302
- package/docs/Assistant CLI.md +65 -65
- package/docs/Backend.md +201 -201
- package/docs/Components.md +140 -140
- package/docs/Creating pages.md +69 -69
- package/docs/Deploy.md +210 -210
- package/docs/Head and SEO.md +139 -139
- package/docs/Javascript.md +126 -126
- package/docs/Styling with SCSS.md +141 -139
- package/nginx.conf +113 -113
- package/package.json +69 -69
- package/src/backend/.htaccess +6 -6
- package/src/backend/_core/composer.json +5 -5
- package/src/backend/_core/composer.lock +492 -492
- package/src/backend/_core/index.js +267 -267
- package/src/backend/_core/index.php +160 -160
- package/src/backend/_core/init.js +52 -52
- package/src/backend/_core/init.php +33 -33
- package/src/backend/_core/modules/RateLimiter.js +58 -58
- package/src/backend/_core/modules/RateLimiter.php +30 -30
- package/src/backend/_core/modules/Response.js +59 -59
- package/src/backend/_core/modules/Response.php +48 -48
- package/src/backend/api/protected/example-protected.js +23 -23
- package/src/backend/api/protected/example-protected.php +16 -16
- package/src/backend/api/public/example-public.js +24 -24
- package/src/backend/api/public/example-public.php +16 -16
- package/src/backend/database/Database.js +46 -46
- package/src/backend/database/Database.php +23 -23
- package/src/backend/example.config.js +37 -37
- package/src/backend/example.config.php +37 -37
- package/src/backend/package.json +17 -17
- package/src/backend/web.config +43 -43
- package/src/frontend/.htaccess +51 -51
- package/src/frontend/404.njk +17 -17
- package/src/frontend/assets/brand/favicon.svg +54 -54
- package/src/frontend/assets/brand/logo.svg +54 -54
- package/src/frontend/components/global/footer.njk +25 -25
- package/src/frontend/components/global/header.njk +6 -6
- package/src/frontend/components/welcome.njk +115 -115
- package/src/frontend/index.njk +8 -8
- package/src/frontend/js/global.js +10 -10
- package/src/frontend/js/modules/exampleModule.js +2 -2
- package/src/frontend/js/pages/404.js +8 -8
- package/src/frontend/js/pages/homepage.js +8 -8
- package/src/frontend/layouts/base.njk +135 -136
- package/src/frontend/layouts/page-components.njk +13 -13
- package/src/frontend/llms.njk +17 -17
- package/src/frontend/robots.njk +7 -7
- package/src/frontend/scss/_global.scss +46 -46
- package/src/frontend/scss/_root.scss +13 -13
- package/src/frontend/scss/modules/_animations.scss +24 -24
- package/src/frontend/scss/modules/_footer.scss +28 -28
- package/src/frontend/scss/modules/_header.scss +26 -26
- package/src/frontend/scss/modules/_mobile.scss +29 -29
- package/src/frontend/scss/modules/_typography.scss +18 -18
- package/src/frontend/scss/modules/frameworks/_bootstrap.scss +109 -109
- package/src/frontend/scss/modules/frameworks/_bulma.scss +108 -108
- package/src/frontend/scss/modules/frameworks/_foundation.scss +137 -137
- package/src/frontend/scss/modules/frameworks/_uikit.scss +109 -109
- package/src/frontend/scss/pages/404.scss +27 -27
- package/src/frontend/scss/pages/homepage.scss +22 -22
- package/src/frontend/sitemap.njk +17 -17
- package/src/frontend/ts/global.ts +11 -11
- package/src/frontend/ts/modules/exampleModule.ts +2 -2
- package/src/frontend/ts/pages/404.ts +8 -8
- package/src/frontend/ts/pages/homepage.ts +8 -8
- package/src/frontend/web.config +51 -51
- package/tools/assistant.js +122 -122
- package/tools/buildJs.js +39 -39
- package/tools/cleanOutput.js +23 -23
- package/tools/cli/prompt.js +40 -40
- package/tools/cli/ui.js +87 -87
- package/tools/config/messages.json +80 -80
- package/tools/config/settings.json +130 -130
- package/tools/lib/colors.js +17 -17
- package/tools/lib/files.js +75 -75
- package/tools/lib/logger.js +22 -22
- package/tools/lib/outputPath.js +141 -141
- package/tools/lib/pageActions.js +146 -146
- package/tools/lib/pageArtifacts.js +46 -46
- package/tools/lib/pageComponents.js +88 -88
- package/tools/lib/pagesData.js +87 -87
- package/tools/lib/paths.js +63 -63
- package/tools/lib/project.js +54 -54
- package/tools/lib/text.js +47 -47
- package/tools/lib/validation.js +40 -40
- package/tools/res/templates/template.js +7 -7
- package/tools/res/templates/template.njk +8 -8
- package/tools/res/templates/template.scss +22 -22
- package/tools/res/templates/template.ts +8 -8
- package/tsconfig.json +24 -24
- package/src/frontend/scss/pages/prova.scss +0 -23
package/docs/Deploy.md
CHANGED
|
@@ -1,211 +1,211 @@
|
|
|
1
|
-
# Deploy
|
|
2
|
-
|
|
3
|
-
Nibula builds a static site into `out`. Publishing means uploading that folder to
|
|
4
|
-
a web server. What you need depends on **where** you publish and **which
|
|
5
|
-
backend** you chose (see `docs/Backend.md`).
|
|
6
|
-
|
|
7
|
-
## The one constraint that decides everything
|
|
8
|
-
|
|
9
|
-
The two backends run in fundamentally different ways:
|
|
10
|
-
|
|
11
|
-
- **PHP** is executed **per request** by the web server through PHP-FPM. There is
|
|
12
|
-
no process to keep alive — the server starts it, it answers, it exits.
|
|
13
|
-
- **Node** **is** the server: a long-running process listening on
|
|
14
|
-
`127.0.0.1:3000`, which the web server reverse-proxies `/api` to. Something has
|
|
15
|
-
to start it and keep it alive across reboots and crashes.
|
|
16
|
-
|
|
17
|
-
This is why **shared hosting cannot run the Node backend**. On Aruba, cPanel and
|
|
18
|
-
similar, you upload files into a web root — you have no shell to start a daemon,
|
|
19
|
-
no systemd, and any process you did manage to launch would be killed. If your
|
|
20
|
-
host is shared hosting, choose PHP. It is not a limitation of Nibula.
|
|
21
|
-
|
|
22
|
-
## Where you can publish
|
|
23
|
-
|
|
24
|
-
| Target | Frontend | PHP backend | Node backend |
|
|
25
|
-
|---|---|---|---|
|
|
26
|
-
| Shared hosting (Apache — Aruba, cPanel) | ✅ | ✅ | ❌ no persistent process |
|
|
27
|
-
| Windows hosting (IIS) | ✅ | ✅ FastCGI | ⚠️ needs ARR reverse proxy |
|
|
28
|
-
| Your own VPS (Nginx on Ubuntu) | ✅ | ✅ | ✅ |
|
|
29
|
-
| Static hosting (Netlify, Vercel, GitHub Pages) | ✅ | ❌ | ❌ |
|
|
30
|
-
|
|
31
|
-
Static hosting serves files and nothing else — fine if your site has no `/api`
|
|
32
|
-
endpoints, unusable otherwise.
|
|
33
|
-
|
|
34
|
-
## Requirements
|
|
35
|
-
|
|
36
|
-
**PHP backend:** a server with PHP support and Composer for the backend
|
|
37
|
-
dependencies.
|
|
38
|
-
|
|
39
|
-
**Node backend:** Node.js 18+ and shell access to run a persistent process — a
|
|
40
|
-
VPS you control.
|
|
41
|
-
|
|
42
|
-
---
|
|
43
|
-
|
|
44
|
-
## Shared hosting (Apache)
|
|
45
|
-
|
|
46
|
-
Upload the **contents of `out`** to the web root (often `htdocs`, `public_html`
|
|
47
|
-
or `www`). Done — `.htaccess` is already inside `out` and Apache reads it
|
|
48
|
-
automatically: directory listing off, 403/404 → `/404.html`, sensitive files
|
|
49
|
-
blocked, backend source sealed, `/api/*` routed.
|
|
50
|
-
|
|
51
|
-
**Backend routing:** if `mod_proxy` is available, `/api` is proxied to Node on
|
|
52
|
-
`127.0.0.1:3000`; if not — the usual case on shared hosting — `/api` is
|
|
53
|
-
rewritten to the PHP front controller. To force PHP on a proxy-enabled server,
|
|
54
|
-
comment the `mod_proxy` block in `.htaccess`.
|
|
55
|
-
|
|
56
|
-
## Windows hosting (IIS)
|
|
57
|
-
|
|
58
|
-
Same idea: upload the contents of `out`, `web.config` is already there and read
|
|
59
|
-
automatically.
|
|
60
|
-
|
|
61
|
-
**Backend routing:** `/api` is rewritten to the PHP front controller. To use the
|
|
62
|
-
Node backend instead, uncomment the `ApiToNode` rule in `web.config` and delete
|
|
63
|
-
`ApiToPhp` — this needs the ARR and URL Rewrite modules with proxying enabled,
|
|
64
|
-
so a server you control, not shared hosting.
|
|
65
|
-
|
|
66
|
-
> ⚠️ **If you chose the Node backend and your host has no ARR** (Aruba and other
|
|
67
|
-
> Windows shared hosting), don't upload the `backend` folder at all. The static
|
|
68
|
-
> site works, and `/api/*` answers with your `404.html`. Upload it and every
|
|
69
|
-
> `/api` request returns an empty 404 instead: IIS rewrites it onto the PHP
|
|
70
|
-
> front controller, which a Node project doesn't contain.
|
|
71
|
-
|
|
72
|
-
---
|
|
73
|
-
|
|
74
|
-
## Your own server (Nginx on a VPS)
|
|
75
|
-
|
|
76
|
-
Nginx doesn't read per-directory config files — the whole site lives in one file.
|
|
77
|
-
Nibula ships `nginx.conf` in the project root as a ready-to-use site file that
|
|
78
|
-
**covers both backends without edits**: `/api` goes to Node, and if Node is
|
|
79
|
-
unreachable the request falls through to PHP automatically.
|
|
80
|
-
|
|
81
|
-
Upload the contents of `out` to `/var/www/SITE_FOLDER`, then follow the steps
|
|
82
|
-
below.
|
|
83
|
-
|
|
84
|
-
### 1. Replace
|
|
85
|
-
|
|
86
|
-
| Placeholder | Where |
|
|
87
|
-
|---|---|
|
|
88
|
-
| `YOUR_DOMAIN` | `server_name`, twice (port 80 and 443) |
|
|
89
|
-
| `SITE_FOLDER` | document root under `/var/www/` |
|
|
90
|
-
| `YOUR_CERTIFICATE` | dir under `/etc/letsencrypt/live/` |
|
|
91
|
-
| `SITE_NAME` | file name in the commands below |
|
|
92
|
-
|
|
93
|
-
### 2. Install (skip if already present)
|
|
94
|
-
|
|
95
|
-
```bash
|
|
96
|
-
sudo apt update
|
|
97
|
-
sudo apt install -y nginx certbot python3-certbot-nginx
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
If you are using PHP as backend:
|
|
101
|
-
|
|
102
|
-
```bash
|
|
103
|
-
sudo apt install -y php-fpm
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
### 3. Certificate
|
|
107
|
-
|
|
108
|
-
```bash
|
|
109
|
-
sudo certbot certonly --nginx --cert-name SITE_NAME -d YOUR_DOMAIN
|
|
110
|
-
sudo systemctl enable --now certbot.timer # auto-renew every 90 days
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
### 4. Install the site
|
|
114
|
-
|
|
115
|
-
```bash
|
|
116
|
-
# Move to nginx folders
|
|
117
|
-
cd /etc/nginx/sites-available
|
|
118
|
-
|
|
119
|
-
# Create and write a new file
|
|
120
|
-
sudo nano SITE_NAME
|
|
121
|
-
# CTRL + O, ENTER, CTRL + X
|
|
122
|
-
|
|
123
|
-
# Copy the config to sites-enabled
|
|
124
|
-
sudo cp SITE_NAME ../sites-enabled/
|
|
125
|
-
|
|
126
|
-
# Test and reload the nginx configuration
|
|
127
|
-
sudo nginx -t && sudo systemctl reload nginx
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
### If it fails
|
|
131
|
-
|
|
132
|
-
| Symptom | Cause |
|
|
133
|
-
|---|---|
|
|
134
|
-
| `cannot load certificate ... Permission denied` | `nginx -t` needs sudo |
|
|
135
|
-
| `cannot load certificate ... No such file` | wrong certificate name |
|
|
136
|
-
| `no alternative certificate subject name` | certificate doesn't cover domain |
|
|
137
|
-
| `unknown directive "http2"` | nginx < 1.25, check with `nginx -v` |
|
|
138
|
-
| NXDOMAIN / timeout during certbot | DNS not pointing here |
|
|
139
|
-
| 500 instead of the 404 page | `404.html` missing |
|
|
140
|
-
| 502 on `/api`, Node deployed | Node process not running |
|
|
141
|
-
| 502 on `/api`, PHP deployed | wrong php-fpm socket path |
|
|
142
|
-
|
|
143
|
-
---
|
|
144
|
-
|
|
145
|
-
## Starting the Node backend on the server
|
|
146
|
-
|
|
147
|
-
After uploading `out`:
|
|
148
|
-
|
|
149
|
-
1. Install the backend's runtime deps:
|
|
150
|
-
```bash
|
|
151
|
-
cd /var/www/SITE_FOLDER/backend
|
|
152
|
-
npm install
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
2. Make sure `config.js` exists in `out/backend/` (copy `example.config.js` if
|
|
156
|
-
missing) and fill in your values.
|
|
157
|
-
|
|
158
|
-
3. Start it in a new screen:
|
|
159
|
-
```bash
|
|
160
|
-
screen -S node-backend
|
|
161
|
-
# In the new screen terminal:
|
|
162
|
-
sudo node /var/www/SITE_FOLDER/backend/_core/index.js
|
|
163
|
-
curl http://127.0.0.1:3000/api/example-public
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
4. Exit the screen without closing the process with `CTRL + A`, `D`. To resume
|
|
167
|
-
the screen type `screen -r node-backend`.
|
|
168
|
-
|
|
169
|
-
5. For production use **systemd**, which also restarts on crash and reboot.
|
|
170
|
-
Create `/etc/systemd/system/backend-node.service`:
|
|
171
|
-
|
|
172
|
-
```ini
|
|
173
|
-
[Unit]
|
|
174
|
-
Description=Nibula Node backend
|
|
175
|
-
After=network.target
|
|
176
|
-
|
|
177
|
-
[Service]
|
|
178
|
-
Type=simple
|
|
179
|
-
User=www-data
|
|
180
|
-
WorkingDirectory=/var/www/SITE_FOLDER/backend
|
|
181
|
-
ExecStart=/usr/bin/node /var/www/SITE_FOLDER/backend/_core/index.js
|
|
182
|
-
Restart=always
|
|
183
|
-
RestartSec=5
|
|
184
|
-
|
|
185
|
-
[Install]
|
|
186
|
-
WantedBy=multi-user.target
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
Adjust `WorkingDirectory` and the `node` path (`which node`), then:
|
|
190
|
-
|
|
191
|
-
```bash
|
|
192
|
-
sudo systemctl daemon-reload
|
|
193
|
-
sudo systemctl enable --now backend-node
|
|
194
|
-
sudo systemctl status backend-node
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
(`pm2` works too: `pm2 start _core/index.js --name backend-node`.)
|
|
198
|
-
|
|
199
|
-
### Environment variables
|
|
200
|
-
|
|
201
|
-
Read by the Node backend at startup. Set them in the systemd unit with
|
|
202
|
-
`Environment=KEY=value`.
|
|
203
|
-
|
|
204
|
-
| Variable | Default | Purpose |
|
|
205
|
-
|---|---|---|
|
|
206
|
-
| `PORT` | `3000` | Port Node listens on (must match the proxy target in `nginx.conf`) |
|
|
207
|
-
| `HOST` | `127.0.0.1` | Bind address — keep it local; the web server is the public face |
|
|
208
|
-
| `DOCUMENT_ROOT` | auto (`SITE_FOLDER/`) | Where `404.html` lives; detected as the folder above `backend/` |
|
|
209
|
-
|
|
210
|
-
Error verbosity is **not** an environment variable: it is the `APP_ENV` key in
|
|
1
|
+
# Deploy
|
|
2
|
+
|
|
3
|
+
Nibula builds a static site into `out`. Publishing means uploading that folder to
|
|
4
|
+
a web server. What you need depends on **where** you publish and **which
|
|
5
|
+
backend** you chose (see `docs/Backend.md`).
|
|
6
|
+
|
|
7
|
+
## The one constraint that decides everything
|
|
8
|
+
|
|
9
|
+
The two backends run in fundamentally different ways:
|
|
10
|
+
|
|
11
|
+
- **PHP** is executed **per request** by the web server through PHP-FPM. There is
|
|
12
|
+
no process to keep alive — the server starts it, it answers, it exits.
|
|
13
|
+
- **Node** **is** the server: a long-running process listening on
|
|
14
|
+
`127.0.0.1:3000`, which the web server reverse-proxies `/api` to. Something has
|
|
15
|
+
to start it and keep it alive across reboots and crashes.
|
|
16
|
+
|
|
17
|
+
This is why **shared hosting cannot run the Node backend**. On Aruba, cPanel and
|
|
18
|
+
similar, you upload files into a web root — you have no shell to start a daemon,
|
|
19
|
+
no systemd, and any process you did manage to launch would be killed. If your
|
|
20
|
+
host is shared hosting, choose PHP. It is not a limitation of Nibula.
|
|
21
|
+
|
|
22
|
+
## Where you can publish
|
|
23
|
+
|
|
24
|
+
| Target | Frontend | PHP backend | Node backend |
|
|
25
|
+
|---|---|---|---|
|
|
26
|
+
| Shared hosting (Apache — Aruba, cPanel) | ✅ | ✅ | ❌ no persistent process |
|
|
27
|
+
| Windows hosting (IIS) | ✅ | ✅ FastCGI | ⚠️ needs ARR reverse proxy |
|
|
28
|
+
| Your own VPS (Nginx on Ubuntu) | ✅ | ✅ | ✅ |
|
|
29
|
+
| Static hosting (Netlify, Vercel, GitHub Pages) | ✅ | ❌ | ❌ |
|
|
30
|
+
|
|
31
|
+
Static hosting serves files and nothing else — fine if your site has no `/api`
|
|
32
|
+
endpoints, unusable otherwise.
|
|
33
|
+
|
|
34
|
+
## Requirements
|
|
35
|
+
|
|
36
|
+
**PHP backend:** a server with PHP support and Composer for the backend
|
|
37
|
+
dependencies.
|
|
38
|
+
|
|
39
|
+
**Node backend:** Node.js 18+ and shell access to run a persistent process — a
|
|
40
|
+
VPS you control.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Shared hosting (Apache)
|
|
45
|
+
|
|
46
|
+
Upload the **contents of `out`** to the web root (often `htdocs`, `public_html`
|
|
47
|
+
or `www`). Done — `.htaccess` is already inside `out` and Apache reads it
|
|
48
|
+
automatically: directory listing off, 403/404 → `/404.html`, sensitive files
|
|
49
|
+
blocked, backend source sealed, `/api/*` routed.
|
|
50
|
+
|
|
51
|
+
**Backend routing:** if `mod_proxy` is available, `/api` is proxied to Node on
|
|
52
|
+
`127.0.0.1:3000`; if not — the usual case on shared hosting — `/api` is
|
|
53
|
+
rewritten to the PHP front controller. To force PHP on a proxy-enabled server,
|
|
54
|
+
comment the `mod_proxy` block in `.htaccess`.
|
|
55
|
+
|
|
56
|
+
## Windows hosting (IIS)
|
|
57
|
+
|
|
58
|
+
Same idea: upload the contents of `out`, `web.config` is already there and read
|
|
59
|
+
automatically.
|
|
60
|
+
|
|
61
|
+
**Backend routing:** `/api` is rewritten to the PHP front controller. To use the
|
|
62
|
+
Node backend instead, uncomment the `ApiToNode` rule in `web.config` and delete
|
|
63
|
+
`ApiToPhp` — this needs the ARR and URL Rewrite modules with proxying enabled,
|
|
64
|
+
so a server you control, not shared hosting.
|
|
65
|
+
|
|
66
|
+
> ⚠️ **If you chose the Node backend and your host has no ARR** (Aruba and other
|
|
67
|
+
> Windows shared hosting), don't upload the `backend` folder at all. The static
|
|
68
|
+
> site works, and `/api/*` answers with your `404.html`. Upload it and every
|
|
69
|
+
> `/api` request returns an empty 404 instead: IIS rewrites it onto the PHP
|
|
70
|
+
> front controller, which a Node project doesn't contain.
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Your own server (Nginx on a VPS)
|
|
75
|
+
|
|
76
|
+
Nginx doesn't read per-directory config files — the whole site lives in one file.
|
|
77
|
+
Nibula ships `nginx.conf` in the project root as a ready-to-use site file that
|
|
78
|
+
**covers both backends without edits**: `/api` goes to Node, and if Node is
|
|
79
|
+
unreachable the request falls through to PHP automatically.
|
|
80
|
+
|
|
81
|
+
Upload the contents of `out` to `/var/www/SITE_FOLDER`, then follow the steps
|
|
82
|
+
below.
|
|
83
|
+
|
|
84
|
+
### 1. Replace
|
|
85
|
+
|
|
86
|
+
| Placeholder | Where |
|
|
87
|
+
|---|---|
|
|
88
|
+
| `YOUR_DOMAIN` | `server_name`, twice (port 80 and 443) |
|
|
89
|
+
| `SITE_FOLDER` | document root under `/var/www/` |
|
|
90
|
+
| `YOUR_CERTIFICATE` | dir under `/etc/letsencrypt/live/` |
|
|
91
|
+
| `SITE_NAME` | file name in the commands below |
|
|
92
|
+
|
|
93
|
+
### 2. Install (skip if already present)
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
sudo apt update
|
|
97
|
+
sudo apt install -y nginx certbot python3-certbot-nginx
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
If you are using PHP as backend:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
sudo apt install -y php-fpm
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### 3. Certificate
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
sudo certbot certonly --nginx --cert-name SITE_NAME -d YOUR_DOMAIN
|
|
110
|
+
sudo systemctl enable --now certbot.timer # auto-renew every 90 days
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### 4. Install the site
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
# Move to nginx folders
|
|
117
|
+
cd /etc/nginx/sites-available
|
|
118
|
+
|
|
119
|
+
# Create and write a new file
|
|
120
|
+
sudo nano SITE_NAME
|
|
121
|
+
# CTRL + O, ENTER, CTRL + X
|
|
122
|
+
|
|
123
|
+
# Copy the config to sites-enabled
|
|
124
|
+
sudo cp SITE_NAME ../sites-enabled/
|
|
125
|
+
|
|
126
|
+
# Test and reload the nginx configuration
|
|
127
|
+
sudo nginx -t && sudo systemctl reload nginx
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### If it fails
|
|
131
|
+
|
|
132
|
+
| Symptom | Cause |
|
|
133
|
+
|---|---|
|
|
134
|
+
| `cannot load certificate ... Permission denied` | `nginx -t` needs sudo |
|
|
135
|
+
| `cannot load certificate ... No such file` | wrong certificate name |
|
|
136
|
+
| `no alternative certificate subject name` | certificate doesn't cover domain |
|
|
137
|
+
| `unknown directive "http2"` | nginx < 1.25, check with `nginx -v` |
|
|
138
|
+
| NXDOMAIN / timeout during certbot | DNS not pointing here |
|
|
139
|
+
| 500 instead of the 404 page | `404.html` missing |
|
|
140
|
+
| 502 on `/api`, Node deployed | Node process not running |
|
|
141
|
+
| 502 on `/api`, PHP deployed | wrong php-fpm socket path |
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## Starting the Node backend on the server
|
|
146
|
+
|
|
147
|
+
After uploading `out`:
|
|
148
|
+
|
|
149
|
+
1. Install the backend's runtime deps:
|
|
150
|
+
```bash
|
|
151
|
+
cd /var/www/SITE_FOLDER/backend
|
|
152
|
+
npm install
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
2. Make sure `config.js` exists in `out/backend/` (copy `example.config.js` if
|
|
156
|
+
missing) and fill in your values.
|
|
157
|
+
|
|
158
|
+
3. Start it in a new screen:
|
|
159
|
+
```bash
|
|
160
|
+
screen -S node-backend
|
|
161
|
+
# In the new screen terminal:
|
|
162
|
+
sudo node /var/www/SITE_FOLDER/backend/_core/index.js
|
|
163
|
+
curl http://127.0.0.1:3000/api/example-public
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
4. Exit the screen without closing the process with `CTRL + A`, `D`. To resume
|
|
167
|
+
the screen type `screen -r node-backend`.
|
|
168
|
+
|
|
169
|
+
5. For production use **systemd**, which also restarts on crash and reboot.
|
|
170
|
+
Create `/etc/systemd/system/backend-node.service`:
|
|
171
|
+
|
|
172
|
+
```ini
|
|
173
|
+
[Unit]
|
|
174
|
+
Description=Nibula Node backend
|
|
175
|
+
After=network.target
|
|
176
|
+
|
|
177
|
+
[Service]
|
|
178
|
+
Type=simple
|
|
179
|
+
User=www-data
|
|
180
|
+
WorkingDirectory=/var/www/SITE_FOLDER/backend
|
|
181
|
+
ExecStart=/usr/bin/node /var/www/SITE_FOLDER/backend/_core/index.js
|
|
182
|
+
Restart=always
|
|
183
|
+
RestartSec=5
|
|
184
|
+
|
|
185
|
+
[Install]
|
|
186
|
+
WantedBy=multi-user.target
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Adjust `WorkingDirectory` and the `node` path (`which node`), then:
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
sudo systemctl daemon-reload
|
|
193
|
+
sudo systemctl enable --now backend-node
|
|
194
|
+
sudo systemctl status backend-node
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
(`pm2` works too: `pm2 start _core/index.js --name backend-node`.)
|
|
198
|
+
|
|
199
|
+
### Environment variables
|
|
200
|
+
|
|
201
|
+
Read by the Node backend at startup. Set them in the systemd unit with
|
|
202
|
+
`Environment=KEY=value`.
|
|
203
|
+
|
|
204
|
+
| Variable | Default | Purpose |
|
|
205
|
+
|---|---|---|
|
|
206
|
+
| `PORT` | `3000` | Port Node listens on (must match the proxy target in `nginx.conf`) |
|
|
207
|
+
| `HOST` | `127.0.0.1` | Bind address — keep it local; the web server is the public face |
|
|
208
|
+
| `DOCUMENT_ROOT` | auto (`SITE_FOLDER/`) | Where `404.html` lives; detected as the folder above `backend/` |
|
|
209
|
+
|
|
210
|
+
Error verbosity is **not** an environment variable: it is the `APP_ENV` key in
|
|
211
211
|
`config.js` / `config.php`. See `docs/Backend.md`.
|