Is there any way for using server-to-server communication?
Unanswered
Red wood ant posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Red wood antOP
I'm glad to see you.
I have a problem that have been bothering me.
In this code, I can't use fetch to use ytdl-core library.
Therefore I have to find ways to use server-to-server communication.
Is there any way for using server-to-server communication?
I have a problem that have been bothering me.
In this code, I can't use fetch to use ytdl-core library.
Therefore I have to find ways to use server-to-server communication.
Is there any way for using server-to-server communication?
![Image](https://cdn.discordapp.com/attachments/1166345638078844948/1166345638703804478/image.png?ex=654a2705&is=6537b205&hm=d2be577e8ec7b343ebc18aae0347eb70ab4c1abad2bce0cf2418cfba4b50396e&)
2 Replies
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
import { NextResponse } from "next/server";
import ytdl from "ytdl-core";
export async function GET() {
const musicStream = ytdl("");
const data = new ReadableStream({
start(controller) {
musicStream.on("data", (chunk: Buffer) =>
controller.enqueue(new Uint8Array(chunk))
);
musicStream.on("end", () => controller.close());
musicStream.on("error", (error: NodeJS.ErrnoException) =>
controller.error(error)
);
},
cancel() {
musicStream.destroy();
},
});
const filename = "example.mp4";
return new NextResponse(data, {
headers: {
"content-disposition": `attachment; filename=${filename}`,
},
});
}
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Red wood antOP
Oh, Thanks.
However I found different way to fix that before.
It is not using NextResponse, but using Response.
This is my code.
However I found different way to fix that before.
It is not using NextResponse, but using Response.
This is my code.
try {
if (url) {
const stream = ytdl(`https://youtube.com/watch?v=${url}`, { filter: 'audioonly', quality: 'highestaudio', format: 'mp3' })
const response = new Response(stream);
return response
}
throw "no datas"
} catch (e) {
return NextResponse.json({ err: e }, { status: 500 })
}