import * as faroe_user_server from "@faroe/user-server";

const actions: faroe_user_server.Actions = {
	// ...
};

const server = new faroe_user_server.Server(actions);

export default defineEventHandler(async (event) => {
	// TODO: Protect route.

	let bodyJSON: string;
	try {
		bodyJSON = await event.req.text();
	} catch {
		return new Response(null, { status: 400 });
	}

	let responseBodyJSON: string;
	try {
		responseBodyJSON = await server.resolveActionInvocationEndpointRequest(bodyJSON);
	} catch {
		return new Response(null, { status: 400 });
	}

	return new Response(responseBodyJSON, {
		headers: {
			"Content-Type": "application/json"
		}
	});
});