RelaySMS Backend
This is a cloud API and User management service. It is directly configurable with MySQL databases for managing users. It also provides out-of-the-box integrations of Google OAuth-2.0, Twitter OAuth, and Telegram endpoints and Account authentication.
- How to set up the Backend
- How to test and deploy with Docker
The most recent version of this guide can be found in the GitHub repository
.
The Backend integrates with these services. You may need to set them up depending on what section you are working on:
Requirements
Installation
All runtime dependencies are installed using npm
npm install
npm install
Troubleshoot
Due to a couple of reasons, users may sometimes experience difficulties in installation. Here are a few troubleshooting guidelines
- Remove the
node_modules
directory and thepackage-lock.json
file. Try installation again.
rm -rf node_modules package-lock.json
Setup
All configuration files are found in the config directory. Configuration files are named according to their environment variables.
Development environment configurations
default.json is the configuration file for a development environment.
To set up Database, API, and platform credentials for a development environment, copy the template files "example.default.json" and rename to "default.json"
cp config/example.default.json config/default.json
Production environment configurations
production.json is the configuration file for a production environment.
To set up Database, API, and platform credentials for a productoin environment, copy the template files "example.production.json" and rename to "production.json"
cp config/example.production.json config/production.json
Configuration Options
These are the options for each configuration file
SEVER
Manages access to the SMS without borders centralize resources and services.
Database
- HOST: The hostname of the database you are connecting to. (Default: localhost)
- USER: The MySQL user to authenticate as. (Default: root)
- PASSWORD: The password of that MySQL user.
- DATABASE: Name of the database to use for this connection (Default: RelaySMS)
API
-
USER MANAGEMENT API PORT: The port number to connect to. (Default: 9000)
-
PUBLISHER API PORT: The port number to connect to. (Default: 10000)
-
KEY: The key used to encrypt a user's data. (Default: "de4053831a43d62d9e68fc11319270a9")
-
SALT: The salt used to hash a user's data. (Default: "acaad78fd9dadcb056840c09073190a8")
-
SECURE SESSIONS: Specifies the boolean value for the Secure Set-Cookie attribute. When truthy, the Secure attribute is set, otherwise it is not. By default, the Secure sessions attribute is set to truthy.
-
SESSION MAXAGE: Specifies the number (in milliseconds) to use when calculating the Expires Set-Cookie attribute. This is done by taking the current server time and adding maxAge milliseconds to the value to calculate an Expires datetime. By default, maximum age is set for two hours (7200000 ms).
-
ENABLE BLOCKING: Specifies the boolean value for tracking user failed authentication attempts.
-
SHORT BLOCK ATTEMPTS: Specifies the number of failed authentication attempts before a short block. Several short blocks results to a long block.
-
LONG BLOCK ATTEMPTS: Specifies the number of failed short block attempts before a long block.
-
SHORT BLOCK DURATION: Specifies the duration (in minutes) of a short block.
-
LONG BLOCK DURATION: Specifies the duration (in minutes) of a long block.
OTP
A user has four attempts to request an OTP code daily
- ENABLE_OTP_BLOCKING: Specifies the boolean value for switching on/off tracking OTP code requests.
- FIRST RESEND DURATION: Specifies the duration (in milliseconds) for the first OTP request.
- SECOND RESEND DURATION: Specifies the duration (in milliseconds) for the second OTP request.
- THIRD RESEND DURATION: Specifies the duration (in milliseconds) for the third OTP request.
- FOURTH RESEND DURATION: Specifies the duration (in milliseconds) for the fourth OTP request.
GATEWAY SERVER
This is a use-case of the [RelaySMS-Gateway-Server]:https://github.com/smswithoutborders/SMSWithoutBorders-Gateway-Server project.
- URL: The URL of the gateway server you are connecting to. (Default: localhost)
- PORT: The port number to connect to. (Default: 6969)
ORIGIN
Configures the Access-Control-Allow-Origin CORS header. Possible values:
Array - set origin to an array of valid origins. Each origin can be a String or a RegExp. For example ["http://example1.com", /.example2.com$/] will accept any request from "http://example1.com" or from a subdomain of "example2.com". (Default: "localhost:18000")
SSL API
- API PORT: The port number to connect to.
- CERTIFICATE: Path to your SSL Certificate.
- KEY: Path to your SSL Key.
- PEM: Path to your SSL PEM.
CREDENTIALS
Acquire credentials from Google Cloud Platform Console
- GOOGLE CLIENT ID: Your Google Client ID
- GOOGLE CLIENT SECRET: Your Google Client Secret
Acquire credentials from Twitter Developers Portal
- TWITTER API KEY: Your Twitter API key
- TWITTER API KEY SECRET: Your Twitter API key Secret
TELEGRAM
This is a use-case of the RelaySMS-customplatform-Telegram project.
- TELEGRAM REQUEST HOST: The URL of the telegram custom platform server you are connecting to.
RECAPTCHA
Acquire KEY from Google reCAPTCHA
- ENABLE RECAPTCHA: Specifies the boolean value for switching on/off recaptcha.
- SECRET KEY: Your Google reCAPTCHA Secret key
DEVELOPER
Manages access to the SMS without borders developers resources.
- HOST: The URL of the developers server you are connecting to. (Default: localhost)
- PORT: The port number to connect to. (Default: 12000)
How to use
Start Backend User management API
User management Development Environment
- With NPM
npm run start_main
- With Node
node controllers/sync_platforms.js && node server.js
User management Production Environment
- With NPM
NODE_ENV=production npm run start_main
- With Node
NODE_ENV=production node controllers/sync_platforms.js && node server.js
Start Backend Publisher API
Publisher Development Environment
- With NPM
npm run start_pub
- With Node
node controllers/sync_platforms.js && node server_pub.js
Publisher Production Environment
- With NPM
NODE_ENV=production npm run start_pub
- With Node
NODE_ENV=production node controllers/sync_platforms.js && node server_pub.js
Start both Backend User management API and Backend Publisher API
Development Environment
- With NPM
npm run start
Production Environment
- With NPM
NODE_ENV=production npm start
API SandBox
http://localhost:{PORT}/v1/api-docs
http://localhost:{PORT}/v2/api-docs
API Logs
By default log levels are set to "info". You can change the default log levels.
For example, For example, Start both Backend User management API and Backend Publisher API with log levels set to "debug". with log levels set to "debug"
LOG_LEVEL=debug npm start
All log files are found in the logs directory. Read more ...