Created
March 1, 2016 19:44
-
-
Save kevinswiber/1d8da9953ef4037e1665 to your computer and use it in GitHub Desktop.
Altering Zetta server response.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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