This is the backend implementation for the Attention Button, handling MQTT communication, authentication, and API requests. It is designed to run behind an Nginx instance that handles TLS termination.
The server expects a config.json
file in the current directory, but you can
override this by setting the TAB_CONFIG_FILE
environment variable.
TAB_CONFIG_FILE=/path/to/config.json node src/main.ts
Alternatively, for development mode:
TAB_ENV=dev node src/main.ts
You can also simply run nodemon
to start a server with live-reloading.
The configuration is defined as a JSON object and an example is given in config.example.json.
smtpHost
: SMTP server hostname.smtpPort
: SMTP server port.smtpUsername
: SMTP authentication username.smtpPassword
: SMTP authentication password.secrets
: Array of secret keys used as the cookie secret.captchaSecret
: Secret key for hCaptcha verification.
hostname
: Defaults to0.0.0.0
.httpPort
: Defaults to8000
.smtpSecure
: Whether to use secure SMTP (true
for TLS,false
for STARTTLS). Defaults tofalse
.storeUrl
: URL for the Attention Button store.mqttPort
: Defaults to1883
.mqttTls
: Iftrue
, additional fieldskeyPath
,certPath
, andcaPath
must be provided for TLS support.
Example for MQTT over TLS:
{
"mqttTls": true,
"keyPath": "/etc/ssl/private/mqtt.key",
"certPath": "/etc/ssl/certs/mqtt.crt",
"caPath": "/etc/ssl/certs/ca.pem"
}
The recommended setup is to run this backend behind an Nginx instance that handles HTTPS termination. Ensure that your Nginx configuration properly proxies requests to the backend.
Contributions are welcome! If you find an issue or want to suggest improvements, feel free to open a pull request.
You can use the hosted instance at theattentionbutton.in.
Acknowledgements
This project uses the following libraries:
- aedes Copyright © 2015 Matteo Collina, The MIT License
- argon2 Copyright © 2015 Ranieri Althoff, The MIT License
- better-sqlite3 Copyright © 2016 Joshua Wise, The MIT License
- better-sqlite3-session-store Copyright © 2020 Tim Daubenschütz, GPL-3.0-only
- cors Copyright © 2013 Troy Goode, The MIT License
- escape-html Copyright © 2012 component, The MIT License
- express Copyright © 2010 TJ Holowaychuk, The MIT License
- express-rate-limit Copyright © 2014 Nathan Friedly, The MIT License
- express-session Copyright © 2014 TJ Holowaychuk, The MIT License
- hcaptcha Copyright © 2018 Juho Hautala, The MIT License
- http-status-codes Copyright © 2013 Bryce Neal, The MIT License
- kysely Copyright © 2021 Sami Koskimäki, The MIT License
- liquidjs Copyright © 2017 Harttle, The MIT License
- nodemailer Copyright © 2011 Andris Reinman, The MIT-0 License
- nodemailer-smtp-transport Copyright © 2014 Andris Reinman, The MIT License
- random-words Copyright © 2013 Apostrophe Technologies, The MIT License
- zod Copyright © 2020 Colin McDonnell, The MIT License
- zod-validation-error Copyright © 2022 Dimitrios C. Michalakos, The MIT License
MIT License. See LICENSE
for details.