init
This commit is contained in:
30
app.js
Normal file
30
app.js
Normal file
@ -0,0 +1,30 @@
|
||||
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;
|
Reference in New Issue
Block a user