forked from jeff-zapotoczny-sonarsource/js-sample
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmyserver.js
More file actions
37 lines (32 loc) · 1012 Bytes
/
myserver.js
File metadata and controls
37 lines (32 loc) · 1012 Bytes
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
const express = require("express");
const bodyParser = require("body-parser");
const axios = require('axios');
const app = express();
const port = process.env.PORT || 5000;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.get("/api/hello", (req, res) => {
console.log("Hello called");
res.send({ express: "Hello From Express" });
});
app.post("/api/world", (req, res) => {
console.log(req.body);
res.send("You sent:" + req.body.post);
axios.get('https://api.example.com/data')
.then(response => {
const externalData = response.data;
res.send({
message: "You sent: " + req.body.post,
externalData: externalData
});
})
.catch(error => {
console.error('Error fetching external data:', error);
res.status(500).send('Error fetching external data');
});
});
app.post("/api/func", (req, res) => {
console.log(req.body);
res.send("You sent:" + req.body.post);
});
app.listen(port, () => console.log(`Listening on port ${port}`));