jChicote / jChicote/Asteroid_Visualizer
Modify proxy to become the server.js
- Dominant language
- JavaScript
- Stars
- 1
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
## Description
Change the proxy-server to be the server.js. Now these will essentially still do a similar job, but will be modified to handle the requests based on details sent from the gateways.
NOTE: The meaning of the gateways change slightly. Now they will act as more of a builder / passthrough. Passing along the details of the request instead of constructing the request.
## Acceptance Criteria
- [ ] Forwards the request to the external API
- [ ] Performs error handling
- [ ] Ensure that the packages are installed relating to the required behavior.
## Implementation
```
const express = require('express');
const cors = require('cors');
const request = require('request'); // Import the 'request' module for making HTTP requests
const app = express();
app.use(cors())
// Define a route that will handle requests to the external API
app.get('/api/nasa', (req, res) => {
const { apiUrl } = req.query;
console.log(apiUrl);
// Forward the request to the external API
request(apiUrl, { json: true }, (err, response, body) => {
if (err) {
return res.status(500).json({ error: 'Error fetching data from API' });
}
res.json(body); // Send the API response to the client
});
});
app.listen(80, function () {
console.log('CORS-enabled web server listening on port 80')
})
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.