Last active
May 6, 2021 14:19
-
-
Save joac/7617ef1409fb399e8293044bc91f1092 to your computer and use it in GitHub Desktop.
Streaming on next
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
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