27 lines
752 B
JavaScript
27 lines
752 B
JavaScript
const cors = require('cors');
|
|
const express = require('express');
|
|
const path = require('path');
|
|
const productController = require('./controller/product.controller');
|
|
|
|
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.get('/', (req, res) => {
|
|
const indexPath = path.join(__dirname, './', 'index.html');
|
|
res.sendFile(indexPath);
|
|
});
|
|
|
|
//Products
|
|
app.get('/api/products', productController.findAll);
|
|
app.get('/api/products/slug/:slug', productController.findBySlug);
|
|
|
|
app.listen(port, () => {
|
|
console.log(`Server listening at http://localhost:${port}`);
|
|
}); |