- nodejs https://nodejs.org/en/ (v6+)
- Heroku Toolbelt https://toolbelt.heroku.com
- git
- PostgreSQL 9.5
Configuration for the notification server is at config/default.js
.
The following parameters can be set in config files or in env variables:
- LOG_LEVEL: the log level
- PORT: the notification server port
- AUTH_SECRET: TC auth secret
- VALID_ISSUERS: TC auth valid issuers
- DATABASE_URL: URI to PostgreSQL database
- DATABASE_OPTIONS: database connection options
- KAFKA_URL: comma separated Kafka hosts
- KAFKA_GROUP_ID: Kafka consumer group id
- KAFKA_CLIENT_CERT: Kafka connection certificate, optional; if not provided, then SSL connection is not used, direct insecure connection is used; if provided, it can be either path to certificate file or certificate content
- KAFKA_CLIENT_CERT_KEY: Kafka connection private key, optional; if not provided, then SSL connection is not used, direct insecure connection is used; if provided, it can be either path to private key file or private key content
- TEMPLATE_MAP: the map between topic and SendGrid template id
Configuration for the connect notification server is at connect/config.js
.
The following parameters can be set in config files or in env variables:
- TEMPLATE_MAP: the map between topic and SendGrid template id
- SUBJECT_MAP: the map between topic and SendGrid email subject
- EMAIL_FROM: from email to use to send email with SendGrid
- SENDGRID_API_KEY: SendGrid API key
Note that the above two configuration are separate because the common notification server config will be deployed to a NPM package, the connect notification server will use that NPM package, the connection notification server should only use API exposed by the index.js.
An admin token is needed to access TC API. This is already configured Postman notification server API environment TC_ADMIN_TOKEN variable. In case it expires, you may get a new token in this way:
- use Chrome to browse connect.topcoder-dev.com
- open developer tools, click the Network tab
- log in with suser1 / Topcoder123, or mess / appirio123
- once logged in, open some project, for example https://connect.topcoder-dev.com/projects/1936 and in the network inspector look for the call to the project api and get the token from the auth header, see http://pokit.org/get/img/68cdd34f3d205d6d9bd8bddb07bdc216.jpg
- for local development environment you can set variables as following:
AUTH_SECRET
,VALID_ISSUERS
can get from tc-project-service configPORT=4001
because connect-app call this port by defaultKAFKA_URL
,KAFKA_CLIENT_CERT
andKAFKA_CLIENT_CERT_KEY
get from tc-bus-api readme
- start local PostgreSQL db, create an empty database, update the config/default.js DATABASE_URL param to point to the db
- install dependencies
npm i
- run code lint check
npm run lint
- start connect notification server
npm start
- the app is running at
http://localhost:4001
, it also starts Kafka consumer to listen for events, send emails using SendGrid and save emails data to database
- git init
- git add .
- git commit -m 'message'
- heroku login
- heroku create [application-name] // choose a name, or leave it empty to use generated one
- heroku addons:create heroku-postgresql:hobby-dev
- note that you may need to wait for several minutes before the PostgreSQL database is ready
- optionally, to set some environment variables in heroku, run command like:
heroku config:set KAFKA_CLIENT_CERT=path/to/certificate/file
heroku config:set KAFKA_CLIENT_CERT_KEY=path/to/private/key/file
heroku config:set KAFKA_GROUP_ID=some-group
etc. - git push heroku master // push code to Heroku
- start the app following above sections
- Import
docs/tc-email-server-api-local-env.postman_environment.json
anddocs/tc-email-server-api.postman_collection.json
to Postman - in Postman, using the email server API collection and environment to run the tests
Swagger API definition is provided at docs/swagger_api.yaml
,
you may check it at http://editor.swagger.io
.