Skip to content

Commit

Permalink
trying to fix this env var nonsense
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdevwords authored and chrisdevwords committed Mar 12, 2017
1 parent 5899c63 commit d3538ad
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import testEnv from './test-env-config';
const TYPE_PRIVATE = 'ephemeral';
const TYPE_PUBLIC = 'in_channel';

const INVALID_TOKEN = 'Token is invalid.'
const INVALID_TOKEN = 'Token is invalid.';

function slackResp(text, code = 200, type = TYPE_PUBLIC) {
return response({
Expand All @@ -18,12 +18,21 @@ function slackResp(text, code = 200, type = TYPE_PUBLIC) {
}, code);
}


function handler(event, context, callback) {

const {
SLACK_TOKEN,
SPOTIFY_LOCAL_URL
} = process.env || testEnv;


let slackToken;

try {
slackToken = process.env.SLACK_TOKEN;
setAPIRoot(process.env.SPOTIFY_LOCAL_URL);
} catch (err) {
slackToken = testEnv.SLACK_TOKEN;
setAPIRoot(testEnv.SPOTIFY_LOCAL_URL);
}


const {
command,
Expand All @@ -32,7 +41,7 @@ function handler(event, context, callback) {
user_name
} = parseFormString(event.body);

if (token !== SLACK_TOKEN) {
if (token !== slackToken) {
callback(null,
slackResp(
INVALID_TOKEN,
Expand All @@ -41,7 +50,7 @@ function handler(event, context, callback) {
)
);
} else {
setAPIRoot(SPOTIFY_LOCAL_URL);

process({ command, text, user_name })
.then((message) => {
callback(null,
Expand Down

0 comments on commit d3538ad

Please sign in to comment.