-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
28 lines (25 loc) · 737 Bytes
/
app.js
File metadata and controls
28 lines (25 loc) · 737 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
const port = process.env.PORT || 3000;
const express = require("express");
const convert = require("xml-js");
const fetch = require("node-fetch");
var app = express();
app.use(express.json());
app.listen(port, err => {
if (err) throw err;
console.log(`> Ready On Server http://localhost:${port}`);
});
app.get("/", function(req, res, next) {
console.log(req);
if (req.query && req.query.q) {
let compact = req.query.compact ? true : false;
fetch(req.query.q)
.then(resp => resp.text())
.then(function(data) {
res.setHeader("Content-Type", "application/json");
res.send(data);
})
.catch(err => console.log(err));
} else {
res.render("index", { title: "Express" });
}
});