Server IP : 162.213.251.212 / Your IP : 3.16.217.46 [ Web Server : LiteSpeed System : Linux business55.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : allssztx ( 535) PHP Version : 8.1.31 Disable Function : NONE Domains : 1 Domains MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/thread-self/root/home/allssztx/www/magdiam-demo/ |
Upload File : |
const express = require('express'); const axios = require('axios'); const cors = require('cors'); const app = express(); const path = require('path') const { uid } = require('uid') app.use(cors()); // Enable CORS for your frontend app.use(express.json()); // Parse JSON bodies app.set('views', path.resolve('./build')) app.use('/magdiam-demo', express.static(path.join(__dirname, 'build'))); // app.use('/magdiam-demo', express.static(path.join(__dirname, 'build'))); app.get('/magdiam-demo/*', async (req, res) => { res.sendFile(path.resolve(__dirname, 'build', 'index.html')); }) app.post('/magdiam-demo/api/products', async (req, res) => { try { const response = await axios.post('https://api.stuller.com/v2/products', req.body, { headers: { 'Content-Type': 'application/json', 'Authorization': `Basic bWFnZGlhbTpQdnBhejEyMw==`, }, }); // console.log(response.data.Products) res.json({ success: true, data: response.data }); console.log('Product Fetched') } catch (error) { console.error('Error fetching data:', error); console.error('Error fetching data:', error.message); res.status(500).json({ message: 'Error fetching data from API' }); } }); app.post('/magdiam-demo/api/diamonds/natural', async (req, res) => { try { const response = await axios.post('https://api.stuller.com/v2/gem/diamonds', req.body, { headers: { 'Content-Type': 'application/json', 'Authorization': `Basic bWFnZGlhbTpQdnBhejEyMw==`, }, }); // console.log(response.data.Products) res.json({ success: true, data: response.data }); console.log('Product Fetched') } catch (error) { console.error('Error fetching data:', error); console.error('Error fetching data:', error.message); res.status(500).json({ message: 'Error fetching data from API' }); } }); app.post('/magdiam-demo/api/diamonds/labcrafted', async (req, res) => { try { const response = await axios.post('https://api.stuller.com/v2/gem/labgrowndiamonds', req.body, { headers: { 'Content-Type': 'application/json', 'Authorization': `Basic bWFnZGlhbTpQdnBhejEyMw==`, }, }); // console.log(response.data.Products) res.json({ success: true, data: response.data }); console.log('Product Fetched') } catch (error) { console.error('Error fetching data:', error); console.error('Error fetching data:', error.message); res.status(500).json({ message: 'Error fetching data from API' }); } }); app.post('/magdiam-demo/api/categories', async (req, res) => { try { // const response = await axios.post('https://api.stuller.com/v2/products/stonefamilies', const response = await axios.post('https://api.stuller.com/v2/products/virtual', req.body, { headers: { 'Content-Type': 'application/json', 'Authorization': `Basic bWFnZGlhbTpQdnBhejEyMw==`, }, }); // console.log(response.data.Products) res.json({ success: true, products: response.data }); } catch (error) { console.error('Error fetching data:', error); console.error('Error fetching data:', error.message); res.status(500).json({ message: 'Error fetching data from API' }); } }); app.post('/magdiam-demo/api/place-order', async (req, res) => { try { const { fullName, email, phone, AddressLine1, AddressLine2, City, State, PostalCode, products } = req.body const formData = { "TestMode": true, "OrderID": uid(), "Account": "428117-000000", "Payment": { "Type": "DefaultPayment" }, "CustomerData": { "OrderNumber": uid(), "OrderDate": new Date().toISOString().split('T')[0] }, "Contact": { "Name": fullName, "Phone": phone, "EmailAddress": email }, "ShipToAddress": { "ShipComplete": true, "ShipMethodType": "UPS_GROUND", "RemovePricing": true, "SignatureRequired": true, "Address": { "Name": fullName, "AddressLine1": AddressLine1, "City": City, "State": State, "PostalCode": PostalCode, "Country": "US" } }, "BillToAddress": { "SameAsShipTo": true }, "Lines": products.map((item) => ({ "Quantity": item.quantity, "Item": item.SKU, "Description": item.Description, "Items": [ { "Number": item.sku || item.SKU, // ✅ Ensures "Number" is present "RingSize": item.ringSize || "" } ] })) }; console.log('formData', JSON.stringify(formData)) const response = await axios.post('https://api.stuller.com/v2/orders/submitorder', formData, { headers: { 'Content-Type': 'application/json', 'Authorization': `Basic bWFnZGlhbTpQdnBhejEyMw==`, }, }) res.json({ success: true, result: response.data }) } catch (error) { res.json({ success: false, error: error.message }) } }) app.listen(5000, () => { console.log('Server is running on port http://localhost:5000/magdiam-demo'); });