forked from Tracy123-gif/emailSender
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
50 lines (37 loc) · 1.27 KB
/
app.js
File metadata and controls
50 lines (37 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import express from 'express';
import path from 'path';
import { fileURLToPath } from 'url';
import dotenv from 'dotenv';
import cors from 'cors';
import contactRoutes from './src/routes/contact.js';
dotenv.config();
const app = express();
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Environment Variables
//const PORT = process.env.PORT || 5000; // Set default port to 5000 if not in .env
//const frontendURL = process.env.FRONTEND_PRODUCTION_URL;
// const allowedOrigins = [frontendURL, 'http://localhost:5173'];
// Middleware: Enable CORS
// app.use(
// cors({
// origin: (origin, callback) => {
// if (!origin || allowedOrigins.includes(origin)) {
// callback(null, true); // Allow the request
// } else {
// callback(new Error('Not allowed by CORS'));
// }
// },
// methods: ['GET', 'POST', 'OPTIONS'], // Allowed HTTP methods
// credentials: true, // Allow cookies if needed
// })
// );
app.use(cors())
// Middleware to parse JSON and URL-encoded data
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// Routes
app.use('/contact', contactRoutes);
// Serve static files
app.use(express.static(path.join(__dirname, 'public')));
export default app;