40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import type {H3Event} from "h3";
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
handleCors(event, {
|
|
origin: '*',
|
|
methods: '*'
|
|
});
|
|
const user = process.env.NUXT_PRIVATE_SUPERUSER_USER;
|
|
const password = process.env.NUXT_PRIVATE_SUPERUSER_PASSWORD;
|
|
if (user == null || password == null)
|
|
{
|
|
console.error("Username or password is null.");
|
|
throw Error();
|
|
}
|
|
|
|
event.headers.delete("host");
|
|
event.headers.delete("origin");
|
|
event.headers.set("authorization", "Basic " + Buffer.from(user + ':' + password).toString('base64'))
|
|
|
|
console.log(event.headers);
|
|
|
|
console.log(process.env.NUXT_PUBLIC_BASE_URL);
|
|
|
|
return sendProxy(event, process.env.NUXT_PUBLIC_BASE_URL + event.path, {
|
|
fetchOptions: {
|
|
method: event.method,
|
|
headers: event.headers,
|
|
body: await readBody(event)
|
|
}
|
|
});
|
|
})
|
|
|
|
async function readBody(event: H3Event)
|
|
{
|
|
if (["POST", "PUT", "PATCH"].includes(event.method))
|
|
{
|
|
return await readRawBody(event);
|
|
}
|
|
return undefined;
|
|
} |