Skip to content

Instantly share code, notes, and snippets.

@oberhamsi
Forked from robi42/proxy.js
Created March 6, 2011 15:32
Show Gist options
  • Save oberhamsi/857360 to your computer and use it in GitHub Desktop.
Save oberhamsi/857360 to your computer and use it in GitHub Desktop.
var http = require('ringo/httpclient');
var {defer} = require('ringo/promise');
var {MemoryStream} = require('io');
var {AsyncResponse} = require('ringo/webapp/async');
var app = exports.app = require('stick').Application()
.configure('error', 'notfound', 'route', 'params');
app.get('/proxy/*', function (request, path) {
var response = new AsyncResponse(request);
// Fetch MP3 from AWS S3.
http.request({
url: 'http://localhost/Music/test.mp3',
async: true,
binary: true,
part: function (bytes) {
response.write(bytes);
response.flush();
}
});
response.start(200, {
'Accept-Ranges': 'bytes',
'Content-Type': 'audio/mp3'
});
return response;
});
if (require.main === module) {
require('stick/server').main(module.id);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment