Don't hard-code production URL in front-end
Closed this issue · 3 comments
Spin-off from #93 (comment). The front-end code currently uses https://donatemask.ca/
for all requests, making it hard to test changes against the server locally.
For example:
https://github.com/mekkim/donatemask/blob/main/src/views/Summary/index.js#L12-L13
https://github.com/mekkim/donatemask/blob/main/server/routes/index.js#L10
https://github.com/mekkim/donatemask/blob/main/server/routes/stripeapi.js#L19-L20
etc
One way to deal with this is to add an environment variable to the config file, and load it at startup. Locally, that can be http://localhost:3000
and in production it can use the real domain.
For reference, this is what needs to be addressed:
rg https://donate
src/components/RequestForm.js
87: fetch("https://donatemask.ca/api/mask_request_add", {
src/views/Summary/index.js
12: const { data: stats } = useSWR("https://donatemask.ca/api/stats", fetcher);
13: const { data: messages } = useSWR("https://donatemask.ca/api/messages", fetcher);
src/components/DonateForm.js
73: action="https://donatemask.ca/create-checkout-session"
README.md
57:- <https://donatemask.ca>
public/index.html
58: <meta property="og:url" content="https://donatemask.ca/">
62: <meta property="og:image" content="https://donatemask.ca/static/media/logo.eb5559fdd02a62715e6846f4951c1186.svg">
67: <meta property="twitter:url" content="https://donatemask.ca/">
70: <meta name="twitter:image" content="https://donatemask.ca/static/media/logo.eb5559fdd02a62715e6846f4951c1186.svg">
server/routes/stripeapi.js
19: success_url: `https://donatemask.ca/order/success?session_id={CHECKOUT_SESSION_ID}`,
20: cancel_url: "https://donatemask.ca/cancel",
46: res.redirect("https://donatemask.ca/donate?success=true");
test/server/routes/stripeapi.test.js
42: .expect("Location", "https://donatemask.ca/donate?success=true");
I'm happy to fix this but I'm not sure what to do? What should it be changed to?
I'll do it, it's not a simple fix. I'll have a PR for it later this week.