queen-raae / gatsby-plugin-donations

A Gatsby Plugin for accepting donations through Stripe 💰
2 stars 1 forks source link

Printing raw js code instead of post request on build #14

Closed multilectical closed 2 years ago

multilectical commented 2 years ago

First off, thanks for this. does just what I need.

I can get this working on develop, but not on build???

On gatsby build, instead of posting to the endpoint, it serves the js, displaying it as code printed to the screen.

Also tried gatsby serve and that correctly pulls up the form.

Here one can see what's going on : https://holobiontlab.org/donate/ . If you click donate, this currently just shows the file contents.

My code is more or less straight from the example :


import React from "react";
const CURRENCY =
  process.env.GATSBY_RAAE_GATSBY_PLUGIN_DONATIONS_STRIPE_CURRENCY;

const CustomDonation = () => {
  return (
    <form action="/api/@raae/gatsby-plugin-donations/donation" method="POST" className="donateBox">
      <fieldset>
        <span>Amount {CURRENCY && `(${CURRENCY})`}:</span><br/>
          <label htmlFor="amount">
          $ <input type="number" id="amount" name="amount" defaultValue="10" />
          </label>    
          <button className="ant-btn-primary ant-btn-round ant-btn-lg">DONATE</button>
      </fieldset>
    </form>
  );
};

export default CustomDonation;

Any hints to figure this out greatly appreciated :)

raae commented 2 years ago

Yeah, it is in use 🎉

multilectical commented 2 years ago

Thanks for the quick reply!

Well, I tried it on a couple local dev machines and where it is live in the link above (a2 hosting cpanel setup, uses litespeed server).

gatsby version 4.3.0

Trying to wrap my head around the difference between build and dev versions. do you have something working on build?

raae commented 2 years ago

To get the plugin to work you will need to deploy on Netlify, Gatsby Cloud or something similar that supports Gatsby Serverless Functions.

multilectical commented 2 years ago

ahh, ok. Thanks.