So my use case is: I want to offer other websites the opportunity to include a JS file that is generated by our Astro site. So website xyz.com will include <script src="our-astro-site.com/example.js" />.
Therefore, I want to create an enpoint in src/pages/example.js.js . This endpoint should respond with a JS file. I can do this now like so:
export const testFunc = () => {
console.log('test');
};
export async function get({ params, request }) {
return new Response('(' + testFunc.toString() + ')()');
}
Which will work. The external site will log "test". But my issue is that all the JS code that this endpoint returns will not be processed/bundled by Astro. I would like to use the full JS authoring experience here (loading modules, minifying, etc.).
How can I make this work?