48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
const cors = require('cors');
|
|
const express = require('express');
|
|
const path = require('path');
|
|
const paypal = require('paypal-rest-sdk');
|
|
const productController = require('./controller/product/product.controller');
|
|
const paymengtController = require('./controller/payment/payment.controller');
|
|
const provincesController = require('./controller/provinces/provinces.controller');
|
|
|
|
paypal.configure({
|
|
'mode': 'sandbox',
|
|
'client_id': process.env.CLIENT_ID,
|
|
'client_secret': process.env.SECRET_KEY
|
|
});
|
|
|
|
const app = express();
|
|
const port = 9999;
|
|
|
|
const allowedOrigins = ['http://localhost:9100', 'https://floranet.onecommerce.dev/'];
|
|
const corsOptions = {
|
|
origin: allowedOrigins,
|
|
optionsSuccessStatus: 200,
|
|
};
|
|
|
|
app.use(cors(corsOptions));
|
|
|
|
app.use(express.json());
|
|
app.use(
|
|
express.urlencoded({
|
|
extended: true,
|
|
}),
|
|
);
|
|
|
|
app.get('/', (req, res) => {
|
|
const indexPath = path.join(__dirname, './', 'index.html');
|
|
res.sendFile(indexPath);
|
|
});
|
|
|
|
//Products
|
|
app.get('/api/products', productController.findAll);
|
|
app.get('/api/products/:id', productController.findById);
|
|
app.post('/api/payment/', paymengtController.Create)
|
|
app.post('/api/payment/success', paymengtController.Success)
|
|
app.get('/api/payment/cancel', paymengtController.Cancel)
|
|
app.get('/api/provinces', provincesController.findAll)
|
|
|
|
app.listen(port, () => {
|
|
console.log(`Server listening at http://localhost:${port}`);
|
|
}); |