How can I return a javascript script that can be used within other websites
Unanswered
Mugger Crocodile posted this in #help-forum
Original message was deleted.
1 Reply
Mugger Crocodile
import { NextApiRequest, NextApiResponse } from "next";
import { NextResponse } from "next/server";
export const GET = async(req:Request, res: Response, {params}: {params: {scriptId: string}}): Promise<NextResponse> => {
console.log(params.scriptId);
const scriptCode = `
function sayHello() {
console.log("'Hello'");
}
`;
return new NextResponse(scriptCode, { headers: { 'Content-Type': 'application/javascript' } });
} I've got this, it works, but I get the following error: TypeError: Cannot destructure property 'params' of 'undefined' as it is undefined.at GET (webpack-internal:///(rsc)/./app/api/script/[scriptId]/route.ts:7:32)
at C:\Users\ursua\Development\nextjs\feedback\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:63815
at C:\Users\ursua\Development\nextjs\feedback\node_modules\next\dist\server\lib\trace\tracer.js:133:36
this is my file structure:
- api
- script
- [scriptId]
- route.ts and the url is /api/script/saaa