-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
42 lines (33 loc) · 1.26 KB
/
Copy pathserver.js
File metadata and controls
42 lines (33 loc) · 1.26 KB
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
38
39
40
41
42
const express = require('express');
const path = require('path');
var request = require('request');
const app = express();
const apiKey = 'BMSw4WMQoJpDhgZUB0lQ';/*process.env.REACT_APP_API_KEY;*/
// Serve the static files from the React app
app.use(express.static(path.join(__dirname, 'client/build')));
// An api endpoint that returns a short list of items
app.get('/api/getBooks', (req, res) => {
const searchText = req.query.searchText;
let url = `https://www.goodreads.com/search/index.xml?key=${apiKey}&q=${searchText}`;
request.get({ url }, function (error, response, body) {
res.json(body);
});
});
app.get('/api/getBookDetails/:bookId', (req, res) => {
const bookId = req.params.bookId;
let url = `https://www.goodreads.com/book/show/${bookId}?key=${apiKey}`;;
request.get({ url }, function (error, response, body) {
res.json(body);
});
});
app.get('/api/getAuthor/:authId', (req, res) => {
debugger;
const authId = req.params.authId;
let url = `https://www.goodreads.com/author/show/${authId}?key=${apiKey}`;;
request.get({ url }, function (error, response, body) {
res.json(body);
});
});
const port = process.env.PORT || 5000;
app.listen(port);
console.log('App is listening on port ' + port);