0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch.git synced 2024-12-23 05:42:59 -05:00
safetwitch/server/routes/proxy/proxyRoute.ts
2023-03-07 01:19:05 -05:00

27 lines
No EOL
705 B
TypeScript

import { Router, Response, Request, NextFunction } from 'express'
const proxyRouter = Router();
proxyRouter.get('/img', async (req: Request, res: Response, next: NextFunction) => {
const imageUrl = req.query.imageUrl?.toString()
if(!imageUrl) return;
fetch(imageUrl).then((response) => {
response.body!.pipeTo(
new WritableStream({
start() {
response.headers.forEach((v, n) => res.setHeader(n, v));
},
write(chunk) {
res.write(chunk);
},
close() {
res.end();
},
})
);
})
.catch((err) => next(err))
})
export default proxyRouter