Anyone Services II

Setting Up Services on the Anyone Network

Integrate SvelteKit with nginx, anon, and anyone-client

This is a follow up from Anon Services I, where we'll give an example of another application set up as a service on the Anyone Network.

"Svelte is a UI framework that uses a compiler to let you write breathtakingly concise components that do minimal work in the browser, using languages you already know โ€” HTML, CSS and JavaScript. Itโ€™s a love letter to web development.

But donโ€™t take our word for it. Developers consistently rank Svelte as the framework theyโ€™re most excited about using."

- https://svelte.dev

Let's start!

If you haven't followed the steps in the previous chapter, go ahead and do so before you continue following along in the instructions below.

Set up nginx for SvelteKit

Create a new nginx configuration for the Svelte service:

sudo nano /etc/nginx/sites-available/anon_service_svelte

Add this configuration to route requests to the Svelte app:

server {
    listen 127.0.0.1:5173;
    server_name localhost;

    root /var/www/my-svelte-anon-app/build;
    allow all;
    index index.js;

    location / {
        try_files $uri $uri/ =404;
    }
}

Enable Svelte and Reload nginx:

Configure anyone-client and anon for Svelte

Add port mapping for Svelte to existing anonrc configuration:

If you followed the steps in Anon Services I, we created our custom anonrc in the ./anon folder. Append the port mapping to the configuration with this command:

Set up and build the SvelteKit application

Create a project directory:

Initialize the project:

See SvelteKit documentation for more information about setting up projects. We chose these options for the example:

Install dependencies:

Configure the SvelteKit Node Adapter:

Edit the svelte.config.js file located in your project folder. Change the import line to import the new adapter-node:

Load environment variables:

Add a .env file with PORT and HOSTNAME:

Build the project:

Move the build output to /var/www/my-svelte-anon-app:

Testing the Svelte-based anon service

Confirm that the app is accessible locally at http://127.0.0.1:5173:

Access the service via SOCKS5:

Hostname located at: ./anon/anon_service/hostname