Я еще новичок в JS да и вовсе в программировании, так что не кидайтесь камнями пожалуйста и объясните почему при таком коде на мой сервер беспрерывно поступают гет запросы?
Это клиентская часть.
А это сервер.
Это клиентская часть.
:
import React, {useState} from 'react';
import axios from 'axios';
import TableLine from "./components/TableLine";
import './App.css'
function App() {
const [prices, setPrices] = useState([])
async function getGoods(){
const response = await axios.get('http://localhost:3000')
setPrices(response.data)
}
getGoods()
return(
<div className="Marakooya">
<table>
<tbody>
{prices.map((price, index) => <TableLine key={index} data={price}/>)}
</tbody>
</table>
</div>
)
}
export default App;
:
import express from 'express'
import mysql from 'mysql2'
import cors from 'cors'
const connection = mysql.createConnection({
host: 'localhost',
user: 'root',
database: 'database'
})
const app = express();
app.use(
cors({
origin: '*'
}
))
app.get('/', (req,res) => {
connection.query('SELECT * from prices', (err, result, fields) => {
console.log(result)
res.json(result)
})
})
app.listen(3000, () => {
console.log('server started on port 3000')
})