forked from KorkanaRahul/OCR_interface
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
33 lines (28 loc) · 980 Bytes
/
server.js
File metadata and controls
33 lines (28 loc) · 980 Bytes
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
const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');
const app = express();
const PORT = process.env.PORT || 3000;
// Middleware for logging requests
app.use((req, res, next) => {
console.log(`[${new Date().toISOString()}] ${req.method} ${req.url}`);
next();
});
// Proxy middleware to forward requests to the target server
app.use(
'/api', // Prefix for the proxy route
createProxyMiddleware({
target: 'http://192.168.137.37:5001', // Replace with your target server
changeOrigin: true, // Needed to handle CORS
pathRewrite: {
'^/api': '', // Remove the '/api' prefix when forwarding the request
},
})
);
// Health check endpoint
app.get('/', (req, res) => {
res.send('Proxy server is running.');
});
// Start the server
app.listen(PORT, () => {
console.log(`Proxy server is running on http://localhost:${PORT}`);
});