App dev with remix template - Best way to process incoming data from the client?

Solved
Danh11
Shopify Partner
62 2 20

Apologies that this isn't exactly on the right board - there isn't any app dev spots to post it in.


I have used the Shopify CLI to create a Remix app. I need to receive customer usage data which will be processed and stored in the prisma DB. This is sent via the shopify app proxy.

 

If I setup a Remix route action to process the data, I receive the data ok but the response to the client is the page of that route. This doesn't seem like the right way to do it.

 

Am I better off running an Express server alongside the Remix app to process the incoming data and push it to the prisma db which the app can then reference? 

I'm new to Remix (and app dev in general), so sorry if there is an obvious answer to this.

Accepted Solution (1)
Danh11
Shopify Partner
62 2 20

This is an accepted solution.

I figured it out.

 

I was returning the component in the jsx file when I should have removed it when using this route as an API to process POST requests. It gets sent to the client as a response instead of the response from the action.

Bad:

import { json } from '@remix-run/node';

export async function action({ request }) {
  try {
    const data = await request.json();
    // process data
    const response = {};
    return json(response);
  } catch (error) {
    // handle error
  }
}

export default function incoming() {
}

 

 

 

Good:

import { json } from '@remix-run/node';

export async function action({ request }) {
  try {
    const data = await request.json();
    // process data
    const response = {};
    return json(response);
  } catch (error) {
    // handle error
  }
}

 

View solution in original post

Replies 3 (3)
Danh11
Shopify Partner
62 2 20

This is an accepted solution.

I figured it out.

 

I was returning the component in the jsx file when I should have removed it when using this route as an API to process POST requests. It gets sent to the client as a response instead of the response from the action.

Bad:

import { json } from '@remix-run/node';

export async function action({ request }) {
  try {
    const data = await request.json();
    // process data
    const response = {};
    return json(response);
  } catch (error) {
    // handle error
  }
}

export default function incoming() {
}

 

 

 

Good:

import { json } from '@remix-run/node';

export async function action({ request }) {
  try {
    const data = await request.json();
    // process data
    const response = {};
    return json(response);
  } catch (error) {
    // handle error
  }
}

 

noiseymur
Shopify Partner
18 1 7

Hey, @Danh11 , do you know how to set up Shopify Remix app with a separate express server or have a template for it by any chance ?

Danh11
Shopify Partner
62 2 20

No, sorry 🙂