Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import express from 'express';
import cors from 'cors';
import dotenv from 'dotenv';
import connectDB from '../config/db.js';
import authRoutes from '../routes/auth.js';
import path from 'path';
import { fileURLToPath } from 'url';
import axios from 'axios';

dotenv.config();
connectDB();

const app = express();
const __filename = fileURLToPath(import.meta.url);
const _dirname = path.dirname(_filename);

const PORT = process.env.PORT || 5000;

// Increase JSON payload limit to allow small avatar images sent as data URLs.
app.use(express.json({ limit: '10mb' }));
app.use(express.urlencoded({ extended: true, limit: '10mb' }));
// Allow cross-origin requests during development (Vite runs on :5174)
app.use(cors({
origin: "*"
}));
// serve public from project root (/server/public)
app.use(express.static(path.join(__dirname, '..', 'public')));
app.use('/api', authRoutes);

app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, '..', 'public', 'index.html'));
});

// Create an axios instance usable from the server. Use the Vite-style env name
// if present on the server, otherwise fall back to localhost.
const API = axios.create({
baseURL: process.env.VITE_API_URL || "http://localhost:5000"
});

app.listen(PORT, () => {
console.log(Server running on http://localhost:${PORT});
});
111 changes: 111 additions & 0 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"axios": "^1.12.2",
"bcrypt": "^5.1.0",
"cors": "^2.8.5",
"dotenv": "^16.0.3",
Expand Down