remix-demo

react router (remix) demo

git clone https://9o.is/git/remix-demo.git

index.ts

(537B)


      1 import type { ActionArgs, LoaderArgs } from "@remix-run/server-runtime";
      2 import { json } from "@remix-run/server-runtime";
      3 import foodEntryController from "~/controllers/foodEntry.server";
      4 
      5 export async function loader({ request }: LoaderArgs) {
      6   return foodEntryController.getAll(request);
      7 }
      8 
      9 export async function action({ request }: ActionArgs) {
     10   switch (request.method) {
     11     case "POST":
     12       return foodEntryController.create(request);
     13 
     14     default:
     15       return json({ error: "Method not supported" }, { status: 405 });
     16   }
     17 }