Skip to content

Instantly share code, notes, and snippets.

@kevinswiber
Created March 1, 2016 19:44
Show Gist options
  • Select an option

  • Save kevinswiber/1d8da9953ef4037e1665 to your computer and use it in GitHub Desktop.

Select an option

Save kevinswiber/1d8da9953ef4037e1665 to your computer and use it in GitHub Desktop.
Altering Zetta server response.
var zetta = require('zetta');
var Photocell = require('zetta-photocell-mock-driver');
zetta()
.use(Photocell)
.link('http://localhost:3000')
.use(function(runtime) {
var argo = runtime.httpServer.cloud;
var serverName = runtime.httpServer.zetta.id;
argo.use(function(handle) {
handle('response', { affinity: 'sink' }, function(env, next) {
if (env.request.url !== '/servers/' + serverName) {
next(env);
return;
}
env.response.getBody(function(err, body) {
if (err) {
next(env);
return;
}
body.links.push({ href: 'http://example.com/zetta/styles', rel: ['stylesheet'] });
env.response.body = body;
next(env);
});
});
});
})
.listen(3001);
var zetta = require('zetta');
var Photocell = require('zetta-photocell-mock-driver');
zetta()
.use(Photocell)
.link('http://localhost:3000')
.use(function(runtime) {
var argo = runtime.httpServer.cloud;
argo.use(function(handle) {
handle('request', function(env, next) {
env.response.setHeader('Link', '<http://example.com/zetta/styles>; rel="stylesheet"');
next(env);
});
});
})
.listen(3001);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment