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
2 changes: 2 additions & 0 deletions server/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Instruct Render to start the server from the src entrypoint
web: node src/index.js
1 change: 1 addition & 0 deletions server/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ <h1>Welcome to Shield X</h1>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>

1 change: 0 additions & 1 deletion server/routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import jwt from 'jsonwebtoken';
import User from '../models/UserR.js';
import authMiddleware from '../middleware/authMiddleware.js';


const router = express.Router();

// Register
Expand Down
11 changes: 10 additions & 1 deletion server/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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();
Expand All @@ -19,7 +20,9 @@ const PORT = process.env.PORT || 5000;
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());
app.use(cors({
origin: "*"
}));
// serve public from project root (/server/public)
app.use(express.static(path.join(__dirname, '..', 'public')));
app.use('/api', authRoutes);
Expand All @@ -28,6 +31,12 @@ 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}`);
});