Lokinet SNApps

How to create and host a SNApp on the Lokinet



Nift is the perfect tool to create, manage and generate your SNApps for Loki's Lokinet, whether it's your first time creating a SNApp or you are making complicated dynamic SNApps with thousands of pages, Nift has you covered. Nift can build basic 10,000 page SNApps in under two seconds (evidence), worry about developing your SNApps rather than frequently waiting for them to build.

This guide will help you publish a SNApp on the Lokinet. See here for documentation on how to install and access the Lokinet. This page should be fairly identical to the Hosting a SNApp documentation page from the Loki docs. See here for template SNApp repositories that you can import/fork/clone to start making SNApss.

1. Preparing your Lokinet address

Depending on your desired outcome you may want to only run a one time SNApp or a SNApp that continues to persistently use the same .loki pubkey.

To create a temporary SNApp continue to 1.1 Temporary SNApp, else if you want to run a persistent SNApp coninue to 1.2 Persistent SNApp.

1.1 Temporary SNApp

When you run ./lokinet your terminal will show a bunch of outputs.

You are looking for the line with lokitun0 in it. The line should look like the following:

[NFO] unnamed (868) Mon Dec 17 15:30:09 2018 AEDT llarp/handlers/tun.cpp:419    default:gtwemaxbfogy5absnjizmoafdngadknpagnoteoir7743ys4xbyo.loki set lokitun0 to have address 172.16.10.1:0

This loki address shown within this output will be the url to your SNApp and the local address to bind SNApps on. You can share the .loki address to individuals who you want to access your SNApp.

You can proceed to 2. Creating your SNApp.

1.2 Persistent SNApp

Open up your lokinet.ini file and add a path to where your SNApp key files will be stored.

sudo nano ~/.lokinet/lokinet.ini

Scroll down to your [network] section and add the following line:

keyfile=/home/<user>/.lokinet/snappkey.private

Replacing <user> with your computer username, alternatively you can set the filepath to wherever you want your SNApp private key to be stored.

Now when you run lokinet within a terminal it will generate your snappkey.private file in the directory you have set.

It will also output your SNApp pubkey which you can share to other individuals who you want accessing your SNApp. Look for the line for your SNApp pubkey:

[NFO] (762) Fri Jan 18 10:05:24 2019 AEDT llarp/handlers/tun.cpp:417    default:sxf7fx9eb4i3u5gyxpkka6wufzfsxyxsuep54c4kqk8axsfo17go.loki set lokitun0 to have address 172.16.10.1:0

In this circumstance your pubkey would be:

sxf7fx9eb4i3u5gyxpkka6wufzfsxyxsuep54c4kqk8axsfo17go.loki

This address will be your SNApp address until you change the path to your SNApps private key.

2. Creating your SNApp

If you have not already, follow these instructions to install Nift. Create a new directory within your home folder, for example on Linux by running the following command in a terminal:

mkdir ~/snapp/

In a terminal, command prompt or power shell window, change directory to the newly created snap directory, for example on linux enter:

cd ~/snapp/

Initialise managing a SNApp with Nift by entering:

nsm init

Open ~/snapp/content/index.content and save the file with the following:

Hello Lokinet

Back in your terminal, command prompt or power shell window enter:

nsm build-updated

You have now created your first SNApp locally, to view your SNApp open up site/index.html.

3. Serving your SNApp

Now we will serve our SNApp to the lokinet, on linux you can do this by running the following command within our snapp folder ~/snapp/site/.

cd ~/snapp/site
sudo python3 -m http.server --bind <ip> <port>

For this example our pubkey is set to lokitun0 which has address 172.16.10.1. The <port> number can be whatever we define it. Therefor the command we would run for this example would be:

sudo python3 -m http.server --bind 172.16.10.1 80

Now if you go to the .loki address you saved before your message “hello lokinet” will be displayed.

Jump onto the Lokinet irc and see if others can access your SNApp.

Finish

Well done, you have finished the guide and your SNApp is served on the Lokinet. For more on Lokinet, see the Lokinet public testing guide. See the Getting Started With Nift Guide for how to edit, manage and generate your SNApps. See here for template SNApp repositories that you can import/fork/clone to start making SNApps.