Skip to content

Commit

Permalink
Added json reply when it no param is given and change the script to a…
Browse files Browse the repository at this point in the history
…sk for permission to deploy route to cloudflare
  • Loading branch information
jiaming committed Mar 21, 2019
1 parent 6959240 commit c1c0938
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
8 changes: 6 additions & 2 deletions api/src/cloudflare-api/mailGetHtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ let config = require("../../config/mailgunConfig")
module.exports = async function(url) {
let mailKey = url.searchParams.get('mailKey')
if (mailKey == null || mailKey === ""){
return new Response('Missing parameter - `mailKey`',
{ status: 400, statusText: 'No `mailKey` param found' });

return new Response("{error: 'No `mailKey` param found'}",
{ status: 400, statusText: 'INVALID_PARAMETER', headers: {
"Content-Type": "application/json"
}
});
}

// Setup the authentication option object
Expand Down
7 changes: 5 additions & 2 deletions api/src/cloudflare-api/mailGetKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ let config = require("../../config/mailgunConfig")
module.exports = async function(url) {
let mailKey = url.searchParams.get('mailKey')
if (mailKey == null || mailKey === ""){
return new Response('Missing parameter - `mailKey`',
{ status: 400, statusText: 'INVALID_PARAMETER' });
return new Response("{error: 'No `mailKey` param found'}",
{ status: 400, statusText: 'INVALID_PARAMETER', headers: {
"Content-Type": "application/json"
}
});
}

// Setup the authentication option object
Expand Down
7 changes: 5 additions & 2 deletions api/src/cloudflare-api/mailList.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ let config = require("../../config/mailgunConfig")
module.exports = async function(url) {
let recipient = url.searchParams.get('recipient')
if (recipient == null){
return new Response('Missing parameter - `recipient`',
{ status: 400, statusText: 'No `recipient` param found' });
return new Response("{error: 'No `recipient` param found'}",
{ status: 400, statusText: 'INVALID_PARAMETER', headers: {
"Content-Type": "application/json"
}
});
}

// strip off all @domain if there is any
Expand Down
11 changes: 8 additions & 3 deletions deploy/cloudflare/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ export CLOUDFLARE_EMAIL="$CLOUDFLARE_EMAIL"
# Calling cloudflare deploy, with parameters passing forward
echo ">> Deploying to cloudflare"
echo
curl -v -X PUT "https://api.cloudflare.com/client/v4/zones/"$CLOUDFLARE_ZONE_ID"/workers/script" -H "X-Auth-Email:$CLOUDFLARE_EMAIL" -H "X-Auth-Key:$CLOUDFLARE_API_KEY" -H "Content-Type:application/javascript" --data-binary "@./dist/main.js"
curl -X PUT "https://api.cloudflare.com/client/v4/zones/"$CLOUDFLARE_ZONE_ID"/workers/script" -H "X-Auth-Email:$CLOUDFLARE_EMAIL" -H "X-Auth-Key:$CLOUDFLARE_API_KEY" -H "Content-Type:application/javascript" --data-binary "@./dist/main.js"

echo ">> Setting route on cloudflare"
curl -X POST "https://api.cloudflare.com/client/v4/zones/"$CLOUDFLARE_ZONE_ID"/workers/filters" -H "X-Auth-Email:$CLOUDFLARE_EMAIL" -H "X-Auth-Key:$CLOUDFLARE_API_KEY" -H "Content-type: application/json" -d '{"pattern": "'$MAILGUN_EMAIL_DOMAIN'/api/*", "enabled": true}'
read -p ">> Set up route on cloudflare? (yes/no)" CLOUDFLARE_SETUP_ROUTE;
if [ "$CLOUDFLARE_SETUP_ROUTE" == "yes" ]; then
echo ">> Setting route on cloudflare"
curl -X POST "https://api.cloudflare.com/client/v4/zones/"$CLOUDFLARE_ZONE_ID"/workers/filters" -H "X-Auth-Email:$CLOUDFLARE_EMAIL" -H "X-Auth-Key:$CLOUDFLARE_API_KEY" -H "Content-type: application/json" -d '{"pattern": "'$MAILGUN_EMAIL_DOMAIN'/api/*", "enabled": true}'
fi

echo ">> Cloudflare script completed"

0 comments on commit c1c0938

Please sign in to comment.