Skip to content

Commit eba5acb

Browse files
authored
Merge pull request #10 from codegratia/RNWS-05
RNWS-05
2 parents 0524b03 + aa2da64 commit eba5acb

File tree

4 files changed

+25
-143
lines changed

4 files changed

+25
-143
lines changed

client/src/App.css

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +0,0 @@
1-
#root {
2-
max-width: 1280px;
3-
margin: 0 auto;
4-
padding: 2rem;
5-
text-align: center;
6-
}
7-
8-
.logo {
9-
height: 6em;
10-
padding: 1.5em;
11-
will-change: filter;
12-
transition: filter 300ms;
13-
}
14-
.logo:hover {
15-
filter: drop-shadow(0 0 2em #646cffaa);
16-
}
17-
.logo.react:hover {
18-
filter: drop-shadow(0 0 2em #61dafbaa);
19-
}
20-
21-
@keyframes logo-spin {
22-
from {
23-
transform: rotate(0deg);
24-
}
25-
to {
26-
transform: rotate(360deg);
27-
}
28-
}
29-
30-
@media (prefers-reduced-motion: no-preference) {
31-
a:nth-of-type(2) .logo {
32-
animation: logo-spin infinite 20s linear;
33-
}
34-
}
35-
36-
.card {
37-
padding: 2em;
38-
}
39-
40-
.read-the-docs {
41-
color: #888;
42-
}

client/src/App.jsx

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,29 @@
1-
import { useState } from 'react'
2-
import reactLogo from './assets/react.svg'
3-
import viteLogo from '/vite.svg'
4-
import './App.css'
1+
import { useEffect, useState } from "react";
2+
import "./App.css";
53

64
function App() {
7-
const [count, setCount] = useState(0)
5+
const [data, setData] = useState(null);
6+
7+
useEffect(() => {
8+
fetch("http://localhost:8000/api/v1/items")
9+
.then((response) => response.json())
10+
.then((data) => setData(data))
11+
.catch((error) => console.error("Error:", error));
12+
}, []);
813

914
return (
10-
<>
11-
<div>
12-
<a href="https://vitejs.dev" target="_blank">
13-
<img src={viteLogo} className="logo" alt="Vite logo" />
14-
</a>
15-
<a href="https://react.dev" target="_blank">
16-
<img src={reactLogo} className="logo react" alt="React logo" />
17-
</a>
18-
</div>
19-
<h1>Vite + React</h1>
20-
<div className="card">
21-
<button onClick={() => setCount((count) => count + 1)}>
22-
count is {count}
23-
</button>
24-
<p>
25-
Edit <code>src/App.jsx</code> and save to test HMR
26-
</p>
27-
</div>
28-
<p className="read-the-docs">
29-
Click on the Vite and React logos to learn more
30-
</p>
31-
</>
32-
)
15+
<div>
16+
<h1>React Node Web Scraper</h1>
17+
{data &&
18+
data.map((item, index) => (
19+
<div key={index}>
20+
<h4>{item.name}</h4>
21+
<img src={item.img} alt={item.name} width={100} height={100} />
22+
<p>{item.price}</p>
23+
</div>
24+
))}
25+
</div>
26+
);
3327
}
3428

35-
export default App
29+
export default App;

client/src/index.css

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +0,0 @@
1-
:root {
2-
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
3-
line-height: 1.5;
4-
font-weight: 400;
5-
6-
color-scheme: light dark;
7-
color: rgba(255, 255, 255, 0.87);
8-
background-color: #242424;
9-
10-
font-synthesis: none;
11-
text-rendering: optimizeLegibility;
12-
-webkit-font-smoothing: antialiased;
13-
-moz-osx-font-smoothing: grayscale;
14-
-webkit-text-size-adjust: 100%;
15-
}
16-
17-
a {
18-
font-weight: 500;
19-
color: #646cff;
20-
text-decoration: inherit;
21-
}
22-
a:hover {
23-
color: #535bf2;
24-
}
25-
26-
body {
27-
margin: 0;
28-
display: flex;
29-
place-items: center;
30-
min-width: 320px;
31-
min-height: 100vh;
32-
}
33-
34-
h1 {
35-
font-size: 3.2em;
36-
line-height: 1.1;
37-
}
38-
39-
button {
40-
border-radius: 8px;
41-
border: 1px solid transparent;
42-
padding: 0.6em 1.2em;
43-
font-size: 1em;
44-
font-weight: 500;
45-
font-family: inherit;
46-
background-color: #1a1a1a;
47-
cursor: pointer;
48-
transition: border-color 0.25s;
49-
}
50-
button:hover {
51-
border-color: #646cff;
52-
}
53-
button:focus,
54-
button:focus-visible {
55-
outline: 4px auto -webkit-focus-ring-color;
56-
}
57-
58-
@media (prefers-color-scheme: light) {
59-
:root {
60-
color: #213547;
61-
background-color: #ffffff;
62-
}
63-
a:hover {
64-
color: #747bff;
65-
}
66-
button {
67-
background-color: #f9f9f9;
68-
}
69-
}

server/app.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const path = require("path");
88

99
const scrapeDynamicWebpage = require("./scrapers/dynamincSiteScraper");
1010
const scrapeStaticWebpage = require("./scrapers/staticSiteScraper");
11-
// const data = require("./data/itemsData.json");
1211

1312
var folder = "./data";
1413

@@ -26,11 +25,11 @@ app.get("/api/v1/items", function (req, res) {
2625
console.error(err);
2726
res.status(500).send(err);
2827
} else {
29-
let data = {};
28+
let data = [];
3029
files.forEach((file) => {
3130
const filePath = path.join("./data", file);
3231
const fileData = JSON.parse(fs.readFileSync(filePath, "utf8"));
33-
data[file] = fileData;
32+
data = data.concat(fileData);
3433
});
3534
res.json(data);
3635
}

0 commit comments

Comments
 (0)