Skip to content

Commit

Permalink
Merge branch 'master' of github.com:humanmade/node-tachyon
Browse files Browse the repository at this point in the history
joehoyle committed Oct 2, 2018
2 parents 032839f + e061412 commit 1600a0e
Showing 2 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ubuntu:latest
FROM ubuntu:trusty
RUN apt-get update && apt-get install -y curl build-essential python2.7
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get update && apt-get -y install nodejs npm
RUN apt-get update && apt-get -y install nodejs
RUN ln -sf /usr/bin/python2.7 /usr/bin/python
CMD cd /build ; npm install --production
38 changes: 38 additions & 0 deletions local-api-gateway.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const http = require('http');
const url = require('url');
const querystring = require('querystring');
const {
spawn
} = require('child_process');


http.createServer(function (request, response) {
const bucket = 'hmn-uploads-eu';
const region = 'eu-west-1';
const task = __dirname;

const pathName = url.parse(request.url).pathname;
const query = url.parse(request.url).query;
const args = {
path: pathName,
queryStringParameters: querystring.parse( query ),
headers: request.headers,
};
const childArgs = ['run', '--rm', '-e', `S3_BUCKET=${ bucket }`, '-e', `S3_REGION=${ region }`, '-v', `${ task }:/var/task`, 'lambci/lambda:nodejs6.10', 'lambda-handler.handler', JSON.stringify(args)];
const child = spawn('docker', childArgs);
var stdout = '';
child.stdout.on('data', data => stdout += data);
child.stderr.on('data', data => console.warn(String(data)));
child.on('close', function () {
const lambdaExec = JSON.parse(stdout);
if ( lambdaExec.errorMessage ) {
response.writeHead( 500 );
response.write(JSON.stringify( lambdaExec ) );
response.end();
return;
}
response.writeHead(lambdaExec.statusCode, lambdaExec.headers);
response.write(Buffer.from(lambdaExec.body, 'base64'));
response.end();
});
}).listen(7000);

0 comments on commit 1600a0e

Please sign in to comment.