claudiajs / claudia-api-builder

Use AWS API Gateway as if it were a lightweight JavaScript web server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Environment variable aka stage dev/prod

aterreno opened this issue · comments

Hi,
I've seen how to figure out if a lambda is in 'dev' or 'prod' from the main claudia.js repository.

exports.handler = function (event, context) {
	var alias = context.invokedFunctionArn.replace(/.*:/g,'');
	context.succeed('executing: ' + alias + ' (version ' + context.functionVersion + ')');
};

What I'd like to do it's the same for an APIBuilder project.

The reason behind this is: something you need to wrap your code (for example, we use IOPipe) but at the same time there are variables that are 'stage' bound and apply to all endpoints, with no context or request.

Removing all routes, this is our setup:

const api = new ApiBuilder({ mergeVars: true });
const iopipe = iopipeLib({
  token:
    'secretToken',
});

api.proxyRouter = iopipe(api.proxyRouter);

module.exports = api;

What we need is to distinguish prod and dev, passing a different token.

const iopipe = iopipeLib({
  token:
    process.env.iopipeToken,
});

Thanks

please use the gitter chat channel for questions https://gitter.im/claudiajs/claudia