diff --git a/Dockerfile b/Dockerfile index 81b7d32..b032ff0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,12 +2,12 @@ # and runs it against the specified Topcoder backend (development or # production) when container is executed. -FROM node:8.2.1 -LABEL app="tc email" version="1.0" +FROM node:6.10 +LABEL app="tc email" version="1.1" WORKDIR /opt/app COPY . . RUN npm install -RUN npm install dotenv --save +#RUN npm install dotenv --save RUN npm run lint CMD ["npm", "start"] diff --git a/README.md b/README.md index 19f49f5..1c2fad6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## Dependencies -- nodejs https://nodejs.org/en/ (v8+) +- nodejs https://nodejs.org/en/ (v6+) - Heroku Toolbelt https://toolbelt.heroku.com - git - PostgreSQL 9.5 diff --git a/config/default.js b/config/default.js index 155638b..fb0a9fa 100644 --- a/config/default.js +++ b/config/default.js @@ -40,4 +40,7 @@ module.exports = { //in every 2 minutes will retry for failed status EMAIL_RETRY_SCHEDULE: process.env.EMAIL_RETRY_SCHEDULE || '0 */2 * * * *', + + API_CONTEXT_PATH: process.env.API_CONTEXT_PATH || '/v5/email', + }; diff --git a/deploy.sh b/deploy.sh index ee48d4d..a833097 100755 --- a/deploy.sh +++ b/deploy.sh @@ -66,6 +66,8 @@ EMAIL_PAUSE_TIME=$(eval "echo \$${ENV}_EMAIL_PAUSE_TIME") EMAIL_RETRY_SCHEDULE=$(eval "echo \"\$${ENV}_EMAIL_RETRY_SCHEDULE\"") DISABLE_LOGGING=$(eval "echo \$${ENV}_DISABLE_LOGGING") +API_CONTEXT_PATH=$(eval "echo \$${ENV}_API_CONTEXT_PATH") + configure_aws_cli() { aws --version aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID @@ -188,6 +190,10 @@ make_task_def(){ { "name": "DISABLE_LOGGING", "value": "%s" + }, + { + "name": "API_CONTEXT_PATH", + "value": "%s" } ], "portMappings": [ @@ -209,7 +215,7 @@ make_task_def(){ ] }' - task_def=$(printf "$task_template" $family $AWS_ACCOUNT_ID $AWS_ECS_CONTAINER_NAME $AWS_ACCOUNT_ID $AWS_REGION $AWS_REPOSITORY $TAG $ENV $AUTH_DOMAIN $AUTH_SECRET $DATABASE_URL $EMAIL_FROM "$JWKS_URI" "$KAFKA_CLIENT_CERT" "$KAFKA_CLIENT_CERT_KEY" $KAFKA_GROUP_ID $KAFKA_URL $LOG_LEVEL $PORT $SENDGRID_API_KEY "$TEMPLATE_MAP" "$VALID_ISSUERS" $EMAIL_MAX_ERRORS $EMAIL_PAUSE_TIME "$EMAIL_RETRY_SCHEDULE" "$DISABLE_LOGGING" $PORT $PORT $AWS_ECS_CLUSTER $AWS_REGION $ENV) + task_def=$(printf "$task_template" $family $AWS_ACCOUNT_ID $AWS_ECS_CONTAINER_NAME $AWS_ACCOUNT_ID $AWS_REGION $AWS_REPOSITORY $TAG $ENV $AUTH_DOMAIN $AUTH_SECRET $DATABASE_URL $EMAIL_FROM "$JWKS_URI" "$KAFKA_CLIENT_CERT" "$KAFKA_CLIENT_CERT_KEY" $KAFKA_GROUP_ID $KAFKA_URL $LOG_LEVEL $PORT $SENDGRID_API_KEY "$TEMPLATE_MAP" "$VALID_ISSUERS" $EMAIL_MAX_ERRORS $EMAIL_PAUSE_TIME "$EMAIL_RETRY_SCHEDULE" "$DISABLE_LOGGING" "$API_CONTEXT_PATH" $PORT $PORT $AWS_ECS_CLUSTER $AWS_REGION $ENV) } diff --git a/package.json b/package.json index aabeec4..e18dbec 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "pg": "^7.3.0", "sequelize": "^4.21.0", "superagent": "^3.8.0", - "tc-core-library-js": "gondzo/tc-core-library-js.git#dev", + "tc-core-library-js": "appirio-tech/tc-core-library-js.git#v2.2", "winston": "^2.4.0" }, "engines": { diff --git a/src/app.js b/src/app.js index c9d2f1c..250f5b1 100644 --- a/src/app.js +++ b/src/app.js @@ -51,7 +51,8 @@ function configureKafkaConsumer(handlers) { return null; } let emailModel = {}; - const messageJSON = JSON.parse(message); + const busPayload = JSON.parse(message); + const messageJSON = busPayload.payload; const handlerAsync = Promise.promisify(handler); // use handler to create notification instances for each recipient return models.Email.create( @@ -189,7 +190,7 @@ function start(handlers) { req.signature = `${def.controller}#${def.method}`; next(); }); - if (url !== '/email/health') { + if (url !== '/health') { actions.push(jwtAuth()); actions.push((req, res, next) => { if (!req.authUser) { @@ -204,7 +205,7 @@ function start(handlers) { }); }); - app.use('/', apiRouter); + app.use(config.API_CONTEXT_PATH, apiRouter); app.use((req, res) => { res.status(404).json({ error: 'route not found' }); diff --git a/src/models/Email.js b/src/models/Email.js index 2b1760b..1c6a3cc 100644 --- a/src/models/Email.js +++ b/src/models/Email.js @@ -13,7 +13,7 @@ module.exports = (sequelize, DataTypes) => sequelize.define('Email', { id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true }, topicName: { type: DataTypes.STRING, allowNull: true, field: 'topic_name' }, - data: { type: DataTypes.STRING, allowNull: false }, + data: { type: DataTypes.TEXT, allowNull: false }, recipients: { type: DataTypes.STRING, allowNull: false }, status: { type: DataTypes.STRING, allowNull: false }, }, {}); diff --git a/src/routes.js b/src/routes.js index c8db8ef..4fe56d5 100644 --- a/src/routes.js +++ b/src/routes.js @@ -1,13 +1,13 @@ 'use strict'; module.exports = { - '/email/templates/eventType/:name': { + '/templates/:name': { get: { controller: 'TemplateController', method: 'eventTypes', }, }, - '/email/health': { + '/health': { get: { controller: 'HealthController', method: 'health',