Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /var/www/html/OTapi/ drwxr-xr-x | |
| Viewing file: Select action/file-type: // index.js
const express = require('express');
const cors = require('cors');
const mongoose = require("mongoose");
const dotenv = require('dotenv');
dotenv.config();
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
const axios = require('axios');
const app = express();
app.use(express.json());
app.use(cors());
app.use(express.json());
const products = require('./routes/products');
app.use(products);
const categories = require('./routes/categories');
app.use(categories);
app.get('/', async (req, res, next) => {
res.json({ message: 'Hello from OTAPI proxy!' });
});
app.get('/item', async (req, res, next) => {
// const result = await callOTAPI('GetCategoryList', {});
try {
const result = await axios.get(`http://otapi.net/service-json/BatchSearchItemsFrame?instanceKey=c4e85fb9-7f86-4091-8d38-73a7b4db3d79&language=&signature=a2ee99e0a0fc25057f08173c0c3906ff6e265179bdb8a27cc7e80127ddcef94f×tamp=20250518073832&sessionId=&xmlParameters=%3CSearchItemsParameters%3E%0D%0A++%3CItemTitle%3E${req.params.keyword}%3C%2FItemTitle%3E%0D%0A++%3CProvider%3EAlibaba1688%3C%2FProvider%3E%0D%0A++%3COrder%3ETotalVolumeDesc%3C%2FOrder%3E%0D%0A%3C%2FSearchItemsParameters%3E%0D%0A&framePosition=0&frameSize=50&blockList=`, null, { })
.then(res => {
console.log('✅ Response:', result.data.CategoryInfoList.Content);
})
.catch(err => {
console.error('❌ Axios Error:', err.message);
});
res.json(result);
} catch (err) {
next(err);
}
});
// // 2. Browse categories & subcategories
// app.get('/categories', async (req, res, next) => {
// try {
// // const result = await callOTAPI('GetCategoryList', {});
// const result = await axios.get('http://otapi.net/service-json/GetRootCategoryInfoList?instanceKey=c4e85fb9-7f86-4091-8d38-73a7b4db3d79&language=en&signature=ded76a2bb903b192aded0891e510ea32dfe7613267bd1be2182362008a1117b0×tamp=20250515142902', null, { })
// .then(result => {
// console.log('✅ Response:', result.data.CategoryInfoList);
// res.json(result);
// })
// .catch(err => {
// console.error('❌ Axios Error:', err.message);
// });
// res.json(result);
// } catch (err) {
// next(err);
// }
// });
// 3. Shop details
app.get('/shops/:shopId', async (req, res, next) => {
try {
const result = await callOTAPI('GetVendorInfo', {
Filter: { VendorId: req.params.shopId }
});
res.json(result);
} catch (err) {
next(err);
}
});
// // 4. Product details (with variants, colors, inventory, rating)
// app.get('/products/:itemId', async (req, res, next) => {
// try {
// const result = await callOTAPI('GetItemFullInfo', {
// ItemId: +req.params.itemId,
// Blocks: ['Item', 'Picture', 'ParamList', 'Stock', 'Price', 'Rating']
// });
// res.json(result);
// } catch (err) {
// next(err);
// }
// });
// Error handler
app.use((err, req, res, next) => {
console.error(err);
res.status(500).json({ error: err.message });
});
const start = async () => {
try {
await mongoose.connect(
process.env.ATLAS_URI
);
// app.listen(PORT, () => console.log(`Server is running on port: ${PORT}`));
const port = process.env.PORT || 4000;
app.listen(port, '0.0.0.0', () => console.log(`OTAPI proxy running on ${port}`));
} catch (error) {
console.error(error);
process.exit(1);
}
};
start();
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0051 ]-- |