31 lines
949 B
JavaScript
31 lines
949 B
JavaScript
const express = require('express');
|
|
const axios = require('axios');
|
|
const { convertToGiteaFormat } = require('./convertData');
|
|
const config = require('./config');
|
|
const log = require('./log');
|
|
|
|
const app = express();
|
|
app.use(express.json());
|
|
|
|
app.get('/oauth/user', async (req, res) => {
|
|
log.info('Received request to /oauth/user', { token: req.query.access_token });
|
|
|
|
try {
|
|
const response = await axios.get(`${config.apiBaseUrl}`, {
|
|
headers: { Authorization: `Bearer ${req.query.access_token}` }
|
|
});
|
|
|
|
const formattedData = convertToGiteaFormat(response.data);
|
|
res.json(formattedData);
|
|
} catch (error) {
|
|
log.error('Error in /oauth/user', { error: error.message });
|
|
res.status(500).json({ error: 'Internal Server Error' });
|
|
}
|
|
});
|
|
|
|
app.listen(config.port, () => {
|
|
log.info(`API transform service listening at http://localhost:${config.port}`);
|
|
});
|
|
|
|
module.exports = app;
|