Skip to content

Commit

Permalink
Add check function
Browse files Browse the repository at this point in the history
HTTP function to check whether the email server is ready to accept
messages.
  • Loading branch information
zuzust committed Jan 31, 2018
1 parent f915004 commit 7076e7a
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 22 deletions.
38 changes: 38 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,46 @@
'use strict';

const nodemailer = require('nodemailer');
const bunyan = require('bunyan');

const config = require('./config.json');


/**
*
*/
exports.ping = (request, response) => {
// Everything is ok
response.status(200).send('Pong!');
};

/**
*
*/
function getTransporter() {
const logger = bunyan.createLogger({ name: 'nodemailer' });
logger.level('trace');

return nodemailer.createTransport({
service: config.transport.service,
auth: config.transport.auth,
logger,
debug: true
});
}

/**
*
*/
exports.check = (request, response) => {
const transporter = getTransporter();

transporter.verify((error, success) => {
if (error) {
console.log(`Error: ${error}`);
response.status(400).send('Error: Server is not ready to accept messages');
} else {
response.status(200).send('Success: Server ready to take our messages');
}
});
}
163 changes: 163 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"remove": "serverless remove"
},
"dependencies": {
"bunyan": "^1.8.12",
"nodemailer": "^4.4.2",
"serverless-google-cloudfunctions": "^1.1.0"
}
}
29 changes: 7 additions & 22 deletions serverless.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
service: ${file(./config.json):SERVICE_ID}
service: ${file(./config.json):service_id}

provider:
name: google
runtime: nodejs
memorySize: 256
timeout: 60s
project: ${file(./config.json):PROJECT_ID}
project: ${file(./config.json):project_id}
# the path to the credentials file needs to be absolute
credentials: ${file(./config.json):CREDENTIALS_FILE}
credentials: ${file(./config.json):credentials_file}

plugins:
- serverless-google-cloudfunctions
Expand All @@ -28,24 +28,9 @@ functions:
events:
- http: path

# NOTE: the following uses an "event" event (pubSub event in this case).
# Please create the corresponding resources in the Google Cloud
# before deploying this service through Serverless

#second:
# handler: event
# events:
# - event:
# eventType: providers/cloud.pubsub/eventTypes/topic.publish
# resource: projects/*/topics/my-topic

# you can define resources, templates etc. the same way you would in a
# Google Cloud deployment configuration
#resources:
# resources:
# - type: storage.v1.bucket
# name: my-serverless-service-bucket
# imports:
# - path: my_template.jinja
check:
handler: check
events:
- http: path

frameworkVersion: "=1.25.0"

0 comments on commit 7076e7a

Please sign in to comment.