-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add version headers to all responses #23
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general looks good. Just add a unit test for this and we are good.
Look at fastify.inject() for that
src/server.test.ts
Outdated
registerRoutes(app); | ||
|
||
// Adding version header | ||
app.addHook('onSend', async (request, reply, payload) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intention with the unit test is to test the implementation in server.ts. I don't really see that this does that?
src/server.ts
Outdated
@@ -9,6 +10,9 @@ const INTERFACE: string = process.env.INTERFACE || '0.0.0.0'; | |||
const app = fastify(); | |||
app.register(FastifyCors, {}); | |||
|
|||
// Add version header | |||
addCustomVersionHeader(app); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer that you add the hook in the registerRoutes()
function because then in the unit test it would be just a matter of doing something like:
describe('Chaos Stream Proxy server', () => {
let app;
beforeEach(() => {
app = fastify();
registerRoutes(app);
});
it.each([HLS_PROXY_MASTER, HLS_PROXY_MEDIA, SEGMENTS_PROXY_SEGMENT])('route %p contains x-version header', (route) => {
const response = await app.inject(route);
expect(response.headers).objectContaining(...)
});
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now. Squash (using rebase) this PR into one single commit and I will merge it to main
82c93a5
to
a86eaf5
Compare
The version header is dynamically updated via npm_package_version, and appended to all other existing headers. By using a Fastify hook, we ensure that the version header gets featured in every proxy response.