https://github.com/block-core/ariton-server
Repo for a future managed server that hosts DWNs and other features for Ariton users
https://github.com/block-core/ariton-server
Last synced: 11 months ago
JSON representation
Repo for a future managed server that hosts DWNs and other features for Ariton users
- Host: GitHub
- URL: https://github.com/block-core/ariton-server
- Owner: block-core
- License: mit
- Created: 2024-11-12T08:51:53.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-12T14:05:35.000Z (over 1 year ago)
- Last Synced: 2025-06-30T09:15:39.539Z (12 months ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ariton-server
Repo for a future managed server that hosts DWNs and other features for Ariton users
## nginx
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:
```nginx
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;
}
}
```
## Running from source
The best option is to run from source:
```sh
git clone REPO
npm install
npm run server
```
## Hosting DWN
Running a DWN Server is a simple process. You can run the server on your local machine or on a remote server.
```sh
npm init
npm install @web5/dwn-server
```
Create a file called `server.js` and add the following code:
```js
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:
# Install build dependencies
```sh
sudo apt-get update
sudo apt-get install -y python3 build-essential gcc make
```
# Clear npm cache
```sh
npm cache clean --force
```
# Retry installation
```sh
npm install better-sqlite3 --build-from-source
```
Then run again:
```sh
npm install @web5/dwn-server
```
If you're still getting errors, try installing additional dependencies:
```sh
sudo apt-get install -y python3-pip python3-dev
```
The issue might also be related to the Node version, then perform the following steps:
# Switch to Node.js LTS (18.x)
```sh
nvm install 18
nvm use 18
```
# Install build dependencies
```sh
sudo apt-get update
sudo apt-get install -y python3 build-essential gcc g++ make
```
# Clear previous build artifacts and cache
```sh
rm -rf node_modules
rm package-lock.json
npm cache clean --force
```
# Reinstall packages
```sh
npm install @web/dwn-server
```
## Linux Service
### Create daemon file
```sh
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
```
```sh
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
```