Spaces:
Sleeping
Sleeping
| const express = require('express'); | |
| const jwt = require('jsonwebtoken'); | |
| const app = express(); | |
| const port = 4001; | |
| const privateKey = process.env.JWT_PRIVATE_KEY; | |
| if (!privateKey) { | |
| console.error('JWT_PRIVATE_KEY environment variable is required'); | |
| process.exit(1); | |
| } | |
| app.get('/auth-token', (req, res) => { | |
| try { | |
| const token = jwt.sign({}, privateKey, { | |
| algorithm: process.env.JWT_ALGORITHM || 'RS256', | |
| expiresIn: '1h' | |
| }); | |
| res.json({ token }); | |
| } catch (error) { | |
| console.error('Error generating token:', error); | |
| res.status(500).json({ error: 'Failed to generate token' }); | |
| } | |
| }); | |
| app.listen(port, () => { | |
| console.log(`Auth service listening on port ${port}`); | |
| }); |