Repo for a future managed server that hosts DWNs and other features for Ariton users
The DWN Server software will add certain HTTP headers to the response, including the Allow-Origin. Hence this should not be added by nginx.
Example nxing site config:
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Add CORS headers
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'dwn-request, Origin, X-Requested-With, Content-Type, Accept, Authorization';
# Handle preflight requests
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'dwn-request, Origin, X-Requested-With, Content-Type, Accept, Authorization';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
}
The best option is to run from source:
git clone REPO
npm install
npm run server
Running a DWN Server is a simple process. You can run the server on your local machine or on a remote server.
npm init
npm install @web5/dwn-server
Create a file called server.js
and add the following code:
import { DwnServer } from '@web5/dwn-server';
const server = new DwnServer();
server.start();
If you get an error during npm install, like an error installing better-sqlite3
, you can fix this by:
sudo apt-get update
sudo apt-get install -y python3 build-essential gcc make
npm cache clean --force
npm install better-sqlite3 --build-from-source
Then run again:
npm install @web5/dwn-server
If you're still getting errors, try installing additional dependencies:
sudo apt-get install -y python3-pip python3-dev
The issue might also be related to the Node version, then perform the following steps:
nvm install 18
nvm use 18
sudo apt-get update
sudo apt-get install -y python3 build-essential gcc g++ make
rm -rf node_modules
rm package-lock.json
npm cache clean --force
npm install @web/dwn-server
touch /etc/system/system/ariton-dwn.service
nano /etc/system/system/ariton-dwn.service
[Unit]
Description=Ariton DWN Daemon
After=network.target
Wants=network-online.target
[Service]
After=network-online.target
Wants=network-online.target
ExecStart=/bin/bash -c 'source /root/.nvm/nvm.sh && nvm install 18.20.4 && nvm use 18.20.4 && export PATH=$PATH && npm run host'
Environment=PATH=/usr/bin
Environment=NODE_ENV=production
WorkingDirectory=/root/dwn-server
User=root
TimeoutSec=120
RestartSec=30
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable ariton-dwn.service
sudo systemctl restart ariton-dwn.service
# See logs
sudo journalctl -u ariton-dwn.service -xe