Help getting started with Caddyserver & Sveltekit app

Hello, could someone please help me with the final step/steps of getting started with Caddy?

I want to host my sveltekit app.

I have downloaded the repo. Then npm install → npm run build

Then in my Caddyfile I added this:
root * /var/www/my-app/build

But when I go to the domain I just see an error message about too many redirects or that it couldn’t be found (404). What am I missing here? :innocent:

Please fill out the help template. We won’t be able to provide constructive feedback without knowing more details.

1 Like

1. The problem I’m having:

Hello, could someone please help me with the final step/steps of getting started with Caddy?
I want to host my sveltekit app. I´m completely new to this whole server stuff so please bear with me! I assume I have either missed some step or something wrong in my config file? Or pointing to the wrong map/file?

I have git cloned my repo and added it to /var/www and then i built it.

2. Error messages and/or full log output:

404 couldnt be found. I think some time it also said too many redirects but not 100% sure.

3. Caddy version:


4. How I installed and ran Caddy:

Through the Ubuntu command lines guide (caddys guide)

a. System environment:

Ubuntu 22.04 and trying to run a Sveltekit app

b. Command:

(for my app)
npm install
npm run build

(for caddy)
sudo systemctl start caddy
sudo systemctl restart caddy

d. My complete Caddy config:
root * /var/www/my-app/build

Please enable the debug logs by adding this to the top of your Caddyfile:


and share the full logs after trying to visit the served website.

I added the debug but i have no idea where to see any debug information from it.

However I did manage to solve the problem.

I was missing the node build command and then I needed to use reverse proxy instead of the files path :slight_smile:

You have to use a static adapter and tell svelte-kit that you want to use a static build:

# Create the svelte (kit) app
$ npm create svelte@latest myapp
$ cd myapp
$ npm install

# Install the adapter and tell svelte to use it
$ npm i @sveltejs/adapter-static      
$ cat svelte.config.js
import adapter from "@sveltejs/adapter-static";

export default {
  kit: {
    adapter: adapter({
      // default options are shown. On some platforms
      // these options are set automatically — see below
      pages: "build",
      assets: "build",
      fallback: null,
      precompress: false,
      strict: false,

# build the project statically
$ npm run build

# Fire the mighty Caddy telling it to serve files statically for hostname localhost 
$ cat Caddyfile 
localhost {
  root * ./build

$ caddy run

But my app is not static. I use the sveltejs/adapter-node and everything seems to work good

Glad to hear is working.

Not sure how that is possible with the caddy file you showed. The node adapter works at network level (listens) and your caddy file tells caddy to serve static files.

Maybe you missed my message above that i updated it to use a reverse proxy instead. This is what my config file looks like now instead :innocent:

    admin off

    log {
        output file /var/log/caddy/access.log
        format json
} {
  reverse_proxy localhost:3000

Ah! That makes sense.

That’s not the Caddyfile you posted initially.

On this last one, you are telling Caddy to proxy the requests to your node server. Caddy is opening a socket to the node server and proxing the requests. In the first Caddyfile, you instructed caddy to map request to files in file system. No networking there. That is why I was confused.

All good. I am glad you are rocking Caddy :+1:.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.