-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
57 lines (44 loc) · 1.44 KB
/
server.js
File metadata and controls
57 lines (44 loc) · 1.44 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
51
52
53
54
55
56
57
const express = require('express');
const path = require('path');
const cors = require('cors');
const app = express();
app.use(cors());
app.options('*', cors()) // include before other routes
const port = 8000; // You can change this to any port you prefer
// Middleware
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// Proxy endpoint for token exchange
app.post('/api/auth/token', async (req, res) => {
try {
const tokenUrl = 'https://oauth2.it.auth.gr/auth/realms/universis/protocol/openid-connect/token';
// Forward the request to the OAuth server
const response = await fetch(tokenUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: new URLSearchParams(req.body).toString()
});
const data = await response.json();
if (!response.ok) {
return res.status(response.status).json(data);
}
res.json(data);
} catch (error) {
console.error('Token proxy error:', error);
res.status(500).json({ error: 'Token exchange failed' });
}
});
/**
* Health check endpoint
*/
app.get('/api/health', (req, res) => {
res.json({ status: 'ok', timestamp: new Date().toISOString() });
});
// Serve static files from the current directory
app.use(express.static(path.join(__dirname, 'public')));
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});
module.exports = app;