Server - Contents

Svelte-PartB

new: 27-Sep-2025

Preparing the Sveltekit on the Virtual Server

Part B (step1): Preliminaries for the Virtual Server

Prepare the Postgres database per PartA (step1) but now on the virtual server. Then having uploaded the revised Svelte app - again with the same Webmin tools, do the same commands as per PartA (step2) in the home directory of the virtual server.

Part B (step2): Install pm2 and its configuration

sammy@imega:$ cd handbk/
sammy@imega /handbk:$ bun install pm2 -g
sammy@imega /handbk:$ vim build/index.js
Change the HOST IP in line: 'const host = env('HOST', '0.0.0.0'); to ... '127.0.0.1 ');
sammy@imega /handbk:$ vim svelte.config.js
Change the trustedOrigin target: ['http://localhost'] to ['https://myexample.com', 'http://localhost']
sammy@imega /handbk:$ vim vit.config.ts
Change the allowedhosts target: ['myexample.com']
sammy@imega /handbk:$ ORIGIN=https://myexample.com DATABASE_URL="postgres://root:mysecretpassword@localhost:5432/testdb" pm2 start build/index.js --name handbk //Ctl-C to exit

Note: As the goal is to deploy the svelte app on an Nginx webserver under your own proper domain (eg. myexample.com), the above settings need to reflect the actual domain. Otherwise, the inbuilt csrf protection in Svelte will prevent activity to the database. To also check the app is being deliver with correct host and port settings, enter this command: pm2 logs handbk, the correct reading should be: http://127.0.0.1:3000

Svelte Svelte-PartB
Svelte-Deploy Svelte-Extras