Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ FRONTEND_DOMAIN_NAME=frontend.example.com
BACKEND_URL=https://backend.example.com
BACKEND_DOMAIN_NAME=backend.example.com

# Set it to true to run the app in Pi Sandbox
SANDBOX_SDK=true

# Obtain the following 2 values on the Pi Developer Portal (https://develop.pinet.com in the Pi Browser).

# Domain validation key:
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ services:
build: ./frontend
environment:
BACKEND_URL: ${BACKEND_URL}
SANDBOX_SDK: ${SANDBOX_SDK}

backend:
build: ./backend
Expand Down
1 change: 0 additions & 1 deletion frontend/.env.development
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
NODE_ENV=development
PORT=3314
VITE_BACKEND_URL=http://localhost:8000
VITE_SANDBOX_SDK=true
9 changes: 4 additions & 5 deletions frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ yarn install

Set `.env.development` with the following variables:

| Variable | Description | Example |
| ------------------ | --------------------- | ----------------------- |
| `PORT` | Dev server port | `3314` |
| `VITE_BACKEND_URL` | Backend API URL | `http://localhost:8000` |
| `VITE_SANDBOX_SDK` | Enable Pi Sandbox SDK | `true` |
| Variable | Description | Example |
| ------------------ | --------------- | ----------------------- |
| `PORT` | Dev server port | `3314` |
| `VITE_BACKEND_URL` | Backend API URL | `http://localhost:8000` |

### 3. Start the development server

Expand Down
2 changes: 0 additions & 2 deletions frontend/docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ set -e

echo "Running Vite React frontend with the following configuration:"
echo "Backend URL: $BACKEND_URL"
echo "Sandbox SDK: $SANDBOX_SDK"

if [ -z "$BACKEND_URL" ]; then
echo "ERROR! INVALID CONFIGURATION: BACKEND_URL must be defined."
Expand All @@ -13,7 +12,6 @@ fi
# Replace placeholders in /var/www/webapp/index.html at runtime
# Use semicolons to avoid conflicts with slashes in URLs
sed -i 's;\$\$BACKEND_URL\$\$;'"${BACKEND_URL}"';g' /var/www/webapp/index.html
sed -i 's;\$\$SANDBOX_SDK\$\$;'"${SANDBOX_SDK}"';g' /var/www/webapp/index.html

# Start nginx
nginx -g "daemon off;"
8 changes: 1 addition & 7 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,14 @@
<script>
window.__ENV = {
backendURL: "$$BACKEND_URL$$",
sandbox: "$$SANDBOX_SDK$$",
};
</script>

<!-- Pi Network SDK -->
<script src="https://sdk.minepi.com/pi-sdk.js"></script>

<script type="module">
const runSDKInSandboxMode = window.__ENV.sandbox === "true";

await Pi.init({
version: "2.0",
sandbox: runSDKInSandboxMode,
});
await Pi.init({ version: "2.0" });
</script>

<title>React App</title>
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/types/window.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ declare global {
interface Window {
__ENV?: {
backendURL?: string;
sandbox?: string;
};
Pi: {
init(options: { version: string }): Promise<void>;

authenticate(scopes: string[], onIncompletePaymentFound: (payment: PaymentDTO) => void): Promise<AuthResult>;

createPayment(
Expand Down
4 changes: 1 addition & 3 deletions frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ export default defineConfig(({ mode }) => {
{
name: "html-env-replace",
transformIndexHtml(html) {
return html
.replace(/\$\$BACKEND_URL\$\$/g, () => env.VITE_BACKEND_URL || "$$BACKEND_URL$$")
.replace(/\$\$SANDBOX_SDK\$\$/g, env.VITE_SANDBOX_SDK || "true");
return html.replace(/\$\$BACKEND_URL\$\$/g, () => env.VITE_BACKEND_URL || "$$BACKEND_URL$$");
},
},
],
Expand Down