From bc95274472217ec0256fdbe481c1bcd4d2392d9a Mon Sep 17 00:00:00 2001 From: tornikegerantia <57709793-tornikegerantia@users.noreply.replit.com> Date: Tue, 14 Apr 2026 21:14:11 +0000 Subject: [PATCH] Add compatibility for Replit environment and local development Update backend server to handle Webflow GraphQL endpoints and CSRF tokens, serve static files correctly, and use 0.0.0.0 host. Add a compatibility script for frontend Webflow e-commerce issues and update HTML files to include it. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 375ec6d3-d5af-4f82-ab81-5c60fd4a86a3 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 05dda85a-ad24-46c8-b27e-50c860b4dd57 Replit-Helium-Checkpoint-Created: true --- .replit | 38 +++++++++++++++++++++++++ backend/server.js | 56 +++++++++++++++++++++++++++++++++++-- company.html | 2 ++ index.html | 2 ++ js/replit-webflow-compat.js | 13 +++++++++ order.html | 2 ++ replit.md | 15 ++++++++++ 7 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 .replit create mode 100644 js/replit-webflow-compat.js create mode 100644 replit.md diff --git a/.replit b/.replit new file mode 100644 index 0000000..b4962bb --- /dev/null +++ b/.replit @@ -0,0 +1,38 @@ +modules = ["web", "nodejs-20"] +[agent] +expertMode = true + +[nix] +channel = "stable-25_05" + +[workflows] +runButton = "Project" + +[[workflows.workflow]] +name = "Project" +mode = "parallel" +author = "agent" + +[[workflows.workflow.tasks]] +task = "workflow.run" +args = "Start application" + +[[workflows.workflow]] +name = "Start application" +author = "agent" + +[[workflows.workflow.tasks]] +task = "shell.exec" +args = "cd backend && npm start" +waitForPort = 5000 + +[workflows.workflow.metadata] +outputType = "webview" + +[[ports]] +localPort = 5000 +externalPort = 80 + +[deployment] +deploymentTarget = "autoscale" +run = ["bash", "-c", "cd backend && npm start"] diff --git a/backend/server.js b/backend/server.js index f3303fe..d607982 100644 --- a/backend/server.js +++ b/backend/server.js @@ -1,16 +1,65 @@ const express = require('express'); const cors = require('cors'); +const path = require('path'); +const crypto = require('crypto'); require('dotenv').config(); const app = express(); +app.set('trust proxy', true); // Middleware app.use(cors()); app.use(express.json()); app.use(express.urlencoded({ extended: true })); +app.post('/.wf_graphql/csrf', (req, res) => { + const token = crypto.randomBytes(16).toString('hex'); + res.cookie('wf-csrf', token, { + httpOnly: false, + sameSite: 'lax', + secure: req.secure, + }); + res.status(204).send(); +}); + +app.post(['/.wf_graphql/apollo', '/.wf_graphql/usys/apollo'], (req, res) => { + res.json({ + data: { + database: { + id: 'local', + commerceOrder: { + comment: null, + extraItems: [], + id: 'local-cart', + startedOn: null, + statusFlags: { + hasDownloads: false, + hasSubscription: false, + isFreeOrder: false, + requiresShipping: false, + }, + subtotal: { decimalValue: '0', string: '$0.00', unit: 'USD', value: 0 }, + total: { decimalValue: '0', string: '$0.00', unit: 'USD', value: 0 }, + updatedOn: null, + userItems: [], + userItemsCount: 0, + }, + }, + site: { + commerce: { + id: 'local-commerce', + businessAddress: { country: 'US' }, + defaultCountry: 'US', + defaultCurrency: 'USD', + quickCheckoutEnabled: false, + }, + }, + }, + }); +}); + // Serve static files from the root directory -app.use(express.static('../')); +app.use(express.static(path.join(__dirname, '..'))); // Basic route app.get('/', (req, res) => { @@ -42,6 +91,7 @@ app.use((req, res) => { // Start server const PORT = process.env.PORT || 5000; -app.listen(PORT, () => { - console.log(`Server running on port ${PORT}`); +const HOST = process.env.HOST || '0.0.0.0'; +app.listen(PORT, HOST, () => { + console.log(`Server running on http://${HOST}:${PORT}`); }); diff --git a/company.html b/company.html index 5e690d3..fe3b136 100644 --- a/company.html +++ b/company.html @@ -15,6 +15,8 @@ +