Allow clients in browsers to call the create API

This commit is contained in:
Eric Allam
2022-05-26 09:15:33 +01:00
parent a4b7a38e67
commit d898d820bb
+23 -2
View File
@@ -1,8 +1,22 @@
import { ActionFunction, json } from "remix";
import { ActionFunction, json, LoaderFunction } from "remix";
import invariant from "tiny-invariant";
import { sendEvent } from "~/graphJSON.server";
import { createFromRawJson, CreateJsonOptions } from "~/jsonDoc.server";
export const loader: LoaderFunction = async ({ request }) => {
if (request.method === "OPTIONS") {
return new Response(null, {
status: 204,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST",
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Max-Age": "86400",
},
});
}
};
export const action: ActionFunction = async ({ request, context }) => {
const url = new URL(request.url);
@@ -42,5 +56,12 @@ export const action: ActionFunction = async ({ request, context }) => {
})
);
return json({ id: doc.id, title, location: url.toString() });
return json(
{ id: doc.id, title, location: url.toString() },
{
headers: {
"Access-Control-Allow-Origin": "*",
},
}
);
};