IBP.email.postman_collection.json
: latest postman collectionIBP.email.postman_environment.json
: latest postman environmentsrc/modules/email/..
: email moduletest_files/sql/email.sql
: sql file to setup email module.eslintrc
: eslintrc, change rules if you think some are not proper.gitignore
: basic gitignore file for node_modulesPrivate API Key
to config/default.json -> mailConfig.mailgunKey
(or environment variable)key-........
Domain Name
to config/default.json -> mailConfig.mailgunDomain
(or environment variable)config/default.json
andconfig/custom-environment-variables.json
,Following variables can be configured:
authSecret
the secret for authport
the port to listenlogLevel
the log level debug
or info
version
the version of apidbConfig
the configurations for database and contains url, pool size and pool idle timeout.You will need to install Heroku Toolbelt for this step if you don't already have it installed.
In the main project folder, run the following commands:
heroku login
git init
git add .
git commit -m "init"
heroku create
heroku addons:create heroku-postgresql:hobby-dev
git push heroku master
heroku logs -t
heroku open
config/default.json
or use environment variable DATABASE_URL.
db_url: postgres://test:test@localhost:5432/test
5432
of your localhost
test
test
test
npm i
npm run lint
npm start
Please follow this article restore
or restore on heroku to restore dump file in test_files\games.psql
.
I actually create sample module to reset database easily you can just configure databae url rightly, start application and run reset request in demo folder in postman.
manually restore required database dump by above guides, or launch postman(after deployed to heroku), goto demo -> reset, click send
emails
execute test_files/sql/email.sql
on heroku postgres.
$ cat test_files/sql/email.sql | heroku pg:psql
---> Connecting to DATABASE_URL
SET
SET
SET
SET
SET
SET
SET
SET
SET
SET
DROP TABLE
CREATE TABLE
GRANT
GRANT
Load postman collection:
postman environment variables:
URL
the base API url for local testing use http://localhost:3000
or heroku app urlTOKEN
sample super role tokenADMIN_TOKEN
sample admin role tokenUSER_TOKEN
sample user role tokenNOROLES_TOKEN
sample user without roles tokenINVALID_TOKEN
sample invalid tokenmailId
id assigned to email, after you sucessfully sent/queued an email you'll be assigned oneaddress
email address to send/receive, because mailgun doesn't support mailing to outside or mailing to many receivers unless you own a domain, this address will be used as sender/receiver. so use your address to verify a mail is sent to you. use the mail address you used in registering to mailgunb64image
topcoder logo encoded in base64 to test image attachment functionalitycheck api/emailApi.yaml
for swagger definition.
POST /emails
endpoint to send an email
to set custom headers:
"headers": [
"x-test-header:1234" <== {{headerName}}:{{headerValue}}
]
to schedule a mail to be sent in the future, set delivery_time
in ISO 8601 date format.
for attachments, content_bytes
should be string in base64 of original binary data.
"attachments": [{
"file_name": "blank.txt",
"file_type": "text",
"content_bytes": "IAo="
}]
after a successful POST to /emails
endpoint, an email ID will be assigned, sample response:
200 Ok
{
"result": {
"success": true,
"code": 200
},
"id": 3
}
use above id
to track delivery status, by /emails/{id}/deliveryStatus
endpoint.
GET /emails/stats
endpoint for tracking Mailgun usage for past 1 month. src/modules/<module name>
src/modules/<module name>/controllers
src/modules/<module name>/services
routes.js
on top, src/modules/<module name>/routes.js
. declare routes to controllers in this file.const service = require('../services/fooService');
to load services from controllers within a module, or import between services within a module.crud
, sample
, mail
src/app-routes.js
will glob src/modules/*/routes.js
and load them. src/app-passport.js
to load passport strategies in src/passports, you can define auth:{name of passport strategy}
in routes.js
of module.access:[role1,role2]
, the user role name is from src/constants.js
.src/app-routes.js
to secure your APIs.