|
| 1 | +"use strict"; |
| 2 | +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { |
| 3 | + if (k2 === undefined) k2 = k; |
| 4 | + var desc = Object.getOwnPropertyDescriptor(m, k); |
| 5 | + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { |
| 6 | + desc = { enumerable: true, get: function() { return m[k]; } }; |
| 7 | + } |
| 8 | + Object.defineProperty(o, k2, desc); |
| 9 | +}) : (function(o, m, k, k2) { |
| 10 | + if (k2 === undefined) k2 = k; |
| 11 | + o[k2] = m[k]; |
| 12 | +})); |
| 13 | +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { |
| 14 | + Object.defineProperty(o, "default", { enumerable: true, value: v }); |
| 15 | +}) : function(o, v) { |
| 16 | + o["default"] = v; |
| 17 | +}); |
| 18 | +var __importStar = (this && this.__importStar) || function (mod) { |
| 19 | + if (mod && mod.__esModule) return mod; |
| 20 | + var result = {}; |
| 21 | + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); |
| 22 | + __setModuleDefault(result, mod); |
| 23 | + return result; |
| 24 | +}; |
| 25 | +var __importDefault = (this && this.__importDefault) || function (mod) { |
| 26 | + return (mod && mod.__esModule) ? mod : { "default": mod }; |
| 27 | +}; |
| 28 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 29 | +const express_1 = __importDefault(require("express")); |
| 30 | +const cors_1 = __importDefault(require("cors")); |
| 31 | +const dotenv = __importStar(require("dotenv")); |
| 32 | +dotenv.config({ path: '.env.dev' }); |
| 33 | +const app = (0, express_1.default)(); |
| 34 | +const PORT = process.env.PORT || 5001; // 5001 to prevent conflicts |
| 35 | +app.use(express_1.default.json()); |
| 36 | +app.use((0, cors_1.default)()); // config cors so that front-end can use |
| 37 | +app.options('*', (0, cors_1.default)()); |
| 38 | +const apiVersion = '/api/v1'; |
| 39 | +// Middleware to handle CORS and preflight requests |
| 40 | +app.use((req, res, next) => { |
| 41 | + res.header('Access-Control-Allow-Origin', '*'); // Allow all origins |
| 42 | + res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization'); |
| 43 | + // Handle preflight (OPTIONS) request before PUT or POST |
| 44 | + if (req.method === 'OPTIONS') { |
| 45 | + res.header('Access-Control-Allow-Methods', 'GET, POST, DELETE, PUT, PATCH'); |
| 46 | + return res.status(200).json({}); |
| 47 | + } |
| 48 | + // Continue to next middleware |
| 49 | + next(); |
| 50 | +}); |
| 51 | +// Start the server |
| 52 | +app.listen(PORT, () => { |
| 53 | + console.log(`Server is running on port ${PORT}`); |
| 54 | +}); |
0 commit comments