User Tools

Site Tools


projets:fuz:spaceapi

SpaceAPI

Project information

  • Owner: Lomanic
  • Participants: you?
  • Status: running
  • Project created on Sat 17-10-20 by Lomanic

Goals

Resources

Example of served JSON:

{
    "api": "0.13",
    "space": "FUZ",
    "logo": "https://fuz.re/WWW.FUZ.RE_fichiers/5c02b2a84373a.png",
    "url": "https://fuz.re/",
    "location": {
        "address": "11-15 rue de la Réunion, Paris 75020, FRANCE",
        "lon": 2.40308,
        "lat": 48.85343
    },
    "contact": {
        "email": "",
        "irc": "",
        "ml": "fuz@fuz.re",
        "twitter": "@fuz_re",
        "matrix": "https://matrix.to/#/#fuz_general:matrix.fuz.re"
    },
    "issue_report_channels": [
        "ml",
        "twitter"
    ],
    "state": {
        "icon": {
            "open": "https://presence.fuz.re/img",
            "closed": "https://presence.fuz.re/img"
        },
        "open": false,
        "message": "open under conditions: https://wiki.fuz.re/doku.php?id=map",
        "lastchange": 1602942506
    },
    "projects": [
        "https://wiki.fuz.re/doku.php?id=projets:fuz:start"
    ]
}

Deployment

On sonic, following what was also done during Online Fuzturday #1 for the presence button API.

sudo adduser spaceapi
sudo passwd -d spaceapi # just in case
cat << EOF | sudo tee /etc/systemd/system/spaceapi.service >/dev/null
[Unit]
Description=SpaceAPI
After=network-online.target
 
[Service]
Type=simple
 
User=spaceapi
Group=spaceapi
WorkingDirectory=/home/spaceapi/
Environment="PORT=3001"
Environment="PRESENCEAPI=https://presence.fuz.re/api"
Environment='SPACEAPI={"api":"0.13","space":"FUZ","logo":"https://fuz.re/WWW.FUZ.RE_fichiers/5c02b2a84373a.png","url":"https://fuz.re/","location":{"address":"11-15 rue dela Réunion, Paris 75020, FRANCE","lon":2.40308,"lat":48.85343},"contact":{"email":"","irc":"","ml":"fuz@fuz.re","twitter":"@fuz_re","matrix":"https://matrix.to/#/#fuz_general:matrix.fuz.re"},"issue_report_channels":["ml","twitter"],"state":{"icon":{"open":"https://presence.fuz.re/img","closed":"https://presence.fuz.re/img"},"message":"open under conditions: https://wiki.fuz.re/doku.php?id=map"},"projects":["https://wiki.fuz.re/doku.php?id=projets:fuz:start"]}'
ExecStart=/home/spaceapi/spaceapi
Restart=on-failure
TimeoutStopSec=300
 
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl enable spaceapi.service
sudo systemctl start spaceapi.service
curl localhost:3001
sudo mkdir -p /var/www/fuz.re/spaceapi/site
sudo certbot certonly --webroot -w /var/www/fuz.re/spaceapi/site -d spaceapi.fuz.re --deploy-hook 'cat "$RENEWED_LINEAGE/privkey.pem" "$RENEWED_LINEAGE/cert.pem" > "$RENEWED_LINEAGE/combined.pem"' --post-hook '/usr/sbin/lighttpd -t -f /etc/lighttpd/lighttpd.conf && service lighttpd reload'

No need to mess with anything else, certbot is already called every ~12 hours as it was installed from Debian repos https://certbot.eff.org/docs/using.html#automated-renewals and lighttpd is reloaded after successful renewal. This config is persistent in /etc/letsencrypt/renewal/spaceapi.fuz.re.conf (automatically created by the previous certbot command), see its doc here.

Corresponding lighttpd vhost config

$HTTP["host"] == "spaceapi.fuz.re" { # added by Lomanic 20201017
    $HTTP["scheme"] == "http" {
        server.document-root = "/var/www/fuz.re/spaceapi/site"
                $HTTP["url"] !~ "^/.well-known/acme-challenge/" {
                        url.redirect = (".*" => "https://${url.authority}${url.path}${qsa}")
                }
    }

        $SERVER["socket"] == ":443" {
                ssl.engine  = "enable"
                proxy.server = ( "" => (("host" => "127.0.0.1", "port" => 3001)) )
                ssl.ca-file = "/etc/letsencrypt/live/spaceapi.fuz.re/chain.pem"
                ssl.pemfile = "/etc/letsencrypt/live/spaceapi.fuz.re/combined.pem"
        }
}

How to run it locally

To be run with

SPACEAPI='{"api":"0.13","space":"FUZ","logo":"https://fuz.re/WWW.FUZ.RE_fichiers/5c02b2a84373a.png","url":"https://fuz.re/","location":{"address":"11-15 rue dela Réunion, Paris 75020, FRANCE","lon":2.40308,"lat":48.85343},"contact":{"email":"","irc":"","ml":"fuz@fuz.re","twitter":"@fuz_re","matrix":"https://matrix.to/#/#fuz_general:matrix.fuz.re"},"issue_report_channels":["ml","twitter"],"state":{"icon":{"open":"https://presence.fuz.re/img","closed":"https://presence.fuz.re/img"},"message":"open under conditions: https://wiki.fuz.re/doku.php?id=map"},"projects":["https://wiki.fuz.re/doku.php?id=projets:fuz:start"]}' PRESENCEAPI=https://presence.fuz.re/api go run main.go

Log

2020-10-17 (in the previous night)

Functional and valid (curl -X POST -H "Content-Type: application/json" https://validator.spaceapi.io/v2/validateJSON -d "$(curl -s localhost:8080)") API in Go, to be published on Github

2020-10-17 (in the evening)

Pushed to GH, made the app fully configurable via env variable, deployed on sonic by following what I (Lomanic) did during the Online Fuzturday #1. Implemented certbot properly for this domain (see Deployment).

projets/fuz/spaceapi.txt · Last modified: 2020/10/18 02:31 by lomanic