Skip to content

Instantly share code, notes, and snippets.

@joac
Last active May 6, 2021 14:19
Show Gist options
  • Save joac/7617ef1409fb399e8293044bc91f1092 to your computer and use it in GitHub Desktop.
Save joac/7617ef1409fb399e8293044bc91f1092 to your computer and use it in GitHub Desktop.
Streaming on next
import { getSession } from 'next-auth/client';
import { NextApiRequest, NextApiResponse } from 'next';
export default async (req: NextApiRequest, res: NextApiResponse) => {
const { pod, container, env } = req.query;
const session = await getSession({ req });
if (!session) {
return res.status(403).end('Forbidden');
}
res.writeHead(200, {
'Content-Type': 'text/plain; charset=utf-8',
'Transfer-Encoding': 'chunked',
});
res.flushHeaders();
const logResponse = await getLogs(
env as string,
pod as string,
container as string,
);
for await (const chunk of logResponse.body) {
res.write(chunk);
await (res as any).flush();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment