Shopify App Proxy Form Woes? A Community Fix!

Decoding the Shopify App Proxy Form Conundrum

Hey everyone! I was digging through the Shopify Community forums the other day and came across a really interesting thread about forms not working correctly within an app proxy. It's a common head-scratcher, so I thought I'd share some insights gleaned from the discussion. The original poster, mikraj, was having trouble getting a form to submit properly from within their app's proxy.

The Problem: Form Submissions Lost in Translation

Essentially, the issue was that the form's action attribute wasn't playing nicely with the app proxy. The poster suspected that the POST request was being sent to the proxied path instead of directly to the app. Here's the code snippet they shared:

import React from "react";
import { Form, useLoaderData, useActionData } from "react-router";
import { authenticate } from "../shopify.server";

/* ------------ loader ------------ */
export async function loader({ request }) {
  await authenticate.public.appProxy(request);

  const url = new URL(request.url);
  const shop = url.searchParams.get("shop") || "unknown";
  const customerId = url.searchParams.get("logged_in_customer_id") || "none";
  const acti
  const pathName = url.pathname;
  const searchParams = url.search;

  return { shop, customerId, actionUrl };
}

/* ------------ action ------------ */
export async function action({ request }) {
  await authenticate.public.appProxy(request);

  const form = await request.formData();
  const message = form.get("message") || "No message";

  return {
    ok: true,
    message: `Form submitted. You sent: ${message}`,
  };
}

/* ------------ component ------------ */
export default function DashboardSimplePage() {
  const { shop, customerId, actionUrl } = useLoaderData();
  const acti

  return (
    

Care Recipients - Test

Rendered by React.

Shop: {shop}

Customer: {customerId}

{actionData?.ok && (

{actionData.message}

)} // not working
// also not working
); }

As you can see, they tried setting the action attribute dynamically with actionUrl and even tried leaving it blank, but neither worked.

The Solution: Hardcoding the App Proxy Path

Thankfully, another community member, simply-forms, chimed in with a straightforward solution: hardcoding the app proxy's path in the form's action attribute. They suggested checking the value of actionUrl to confirm it's the relative path configured in the app's proxy.

So, the fix involves a bit of detective work and a little bit of hardcoding. Here's how you can tackle this:

  1. Inspect the actionUrl: Use console.log(actionUrl) to see what the value of actionUrl actually is. This will help you understand where the form is trying to submit.
  2. Verify Your App Proxy Settings: Double-check your app proxy settings in your Shopify Partner Dashboard. Make sure the subdomain and path are configured correctly.
  3. Hardcode the Path (if necessary): If the actionUrl isn't resolving correctly, try hardcoding the relative path from your app proxy settings into the form's action attribute. For example:

Replace /apps/your-app-proxy-path with the actual path you've configured in your app proxy settings.

Why This Works

The app proxy essentially creates a tunnel between your Shopify store and your app. By hardcoding the correct path, you're ensuring that the form submission goes through that tunnel directly to your app, bypassing any potential routing issues.

It might not be the most elegant solution, but it's a practical one that seems to work in many cases. Of course, you'll want to keep an eye on your app proxy settings and update the hardcoded path if anything changes.

This thread highlights the power of community problem-solving. Sometimes the simplest solutions are the most effective, and it's great to see people sharing their experiences and helping each other out. Hopefully, this helps you get your Shopify app proxy forms working smoothly!

Share:

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools