У меня уже есть сервер, который обрабатывает запросы на логин. Тебе надо туда добавить: GET request to get/search a list of cards. arraycards.jsx: import springBootLogo from '../../../../img/spring-boot.svg';
import springFrameworkLogo from '../../../../img/spring-framework.svg';
import springDataLogo from '../../../../img/spring-data.svg';
import springCloudLogo from '../../../../img/spring-cloud.svg';
import springDataFlowLogo from '../../../../img/spring-data-flow.svg';
import springSecurityLogo from '../../../../img/spring-security.svg';
import style from './cardsarray.module.css';
export const CARDS = [
{
id: 1,
card: {
cardClass: style.main__card,
image: {
imageClass: style.main__card_image,
alt: 'Spring Boot Logo',
src: springBootLogo
},
text: {
heading: 'Spring Boot',
description:
'Provides core support for dependency injection, transaction management, web apps, data access, messaging, and more.'
}
}
},
{
id: 2,
card: {
cardClass: style.main__card,
image: {
imageClass: style.main__card_image,
alt: 'Spring Framework Logo',
src: springFrameworkLogo
},
text: {
heading: 'Spring Framework',
description:
'Takes an opinionated view of building Spring applications and gets you up and running as quickly as possible.'
}
}
},
{
id: 3,
card: {
cardClass: style.main__card,
image: {
imageClass: style.main__card_image,
alt: 'Spring Data Logo',
src: springDataLogo
},
text: {
heading: 'Spring Data',
description:
'Provides a consistent approach to data access - relational, non-relational, map-reduce, and beyond.'
}
}
},
{
id: 4,
card: {
cardClass: style.main__card,
image: {
imageClass: style.main__card_image,
alt: 'Spring Cloud Logo',
src: springCloudLogo
},
text: {
heading: 'Spring Cloud',
description:
'Provides a set of tools for common patterns in distributed systems. Useful for building and deploying microservices.'
}
}
},
{
id: 5,
card: {
cardClass: style.main__card,
image: {
imageClass: style.main__card_image,
alt: 'Spring Cloud Data Flow Logo',
src: springDataFlowLogo
},
text: {
heading: 'Spring Cloud Data Flow',
description:
'Provides an orchestration service for composable data microservice applications on modern runtimes.'
}
}
},
{
id: 6,
card: {
cardClass: style.main__card,
image: {
imageClass: style.main__card_image,
alt: 'Spring Security Logo',
src: springSecurityLogo
},
text: {
heading: 'Spring Security',
description:
'Protects your application with comprehensive and extensible authentication and authorization support.'
}
}
}
];
CardSection.jsx import React, { useCallback, useContext } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { filterCards, setSearchValue } from '../../../Redux/actions';
import { SearchInput } from '../SearchInput/SearchInput';
import { Card } from '../Card/Card';
import { ThemeContext } from '../../../Selector/ThemeContext';
import classNames from 'classnames';
import style from './CardSection.module.css';
app.listen(PORT, () => {
console.log(Server is running on port ${PORT});
}); arraycards.jsx: import springBootLogo from '../../../../img/spring-boot.svg';
import springFrameworkLogo from '../../../../img/spring-framework.svg';
import springDataLogo from '../../../../img/spring-data.svg';
import springCloudLogo from '../../../../img/spring-cloud.svg';
import springDataFlowLogo from '../../../../img/spring-data-flow.svg';
import springSecurityLogo from '../../../../img/spring-security.svg';
import style from './cardsarray.module.css';
export const CARDS = [
{
id: 1,
card: {
cardClass: style.main__card,
image: {
imageClass: style.main__card_image,
alt: 'Spring Boot Logo',
src: springBootLogo
},
text: {
heading: 'Spring Boot',
description:
'Provides core support for dependency injection, transaction management, web apps, data access, messaging, and more.'
}
}
},
{
id: 2,
card: {
cardClass: style.main__card,
image: {
imageClass: style.main__card_image,
alt: 'Spring Framework Logo',
src: springFrameworkLogo
},
text: {
heading: 'Spring Framework',
description:
'Takes an opinionated view of building Spring applications and gets you up and running as quickly as possible.'
}
}
},
{
id: 3,
card: {
cardClass: style.main__card,
image: {
imageClass: style.main__card_image,
alt: 'Spring Data Logo',
src: springDataLogo
},
text: {
heading: 'Spring Data',
description:
'Provides a consistent approach to data access - relational, non-relational, map-reduce, and beyond.'
}
}
},
{
id: 4,
card: {
cardClass: style.main__card,
image: {
imageClass: style.main__card_image,
alt: 'Spring Cloud Logo',
src: springCloudLogo
},
text: {
heading: 'Spring Cloud',
description:
'Provides a set of tools for common patterns in distributed systems. Useful for building and deploying microservices.'
}
}
},
{
id: 5,
card: {
cardClass: style.main__card,
image: {
imageClass: style.main__card_image,
alt: 'Spring Cloud Data Flow Logo',
src: springDataFlowLogo
},
text: {
heading: 'Spring Cloud Data Flow',
description:
'Provides an orchestration service for composable data microservice applications on modern runtimes.'
}
}
},
{
id: 6,
card: {
cardClass: style.main__card,
image: {
imageClass: style.main__card_image,
alt: 'Spring Security Logo',
src: springSecurityLogo
},
text: {
heading: 'Spring Security',
description:
'Protects your application with comprehensive and extensible authentication and authorization support.'
}
}
}
];
Чтобы добавить GET-запрос для получения и поиска списка карточек, вам нужно переместить данные карточек на сервер и настроить клиентское приложение для получения этих данных с сервера по API-запросу. Вот пошаговое руководство по тому, как это сделать:
ШАГ 1: Перенесите данные карточек на сервер
Создайте файл projects.js на сервере:
Создайте файл projects.js в корневой директории вашего сервера (там же, где находится index.js). Этот файл будет экспортировать массив с данными карточек.
// projects.js
module.exports = [
{
id: 1,
card: {
cardClass: 'main__card',
image: {
imageClass: 'main__card_image',
alt: 'Spring Boot Logo',
src: '/images/spring-boot.svg', // Обратите внимание на путь
},
text: {
heading: 'Spring Boot',
description:
'Provides core support for dependency injection, transaction management, web apps, data access, messaging, and more.',
},
},
},
// ... остальные карточки
];
Настройте сервер для раздачи статических файлов (изображений):
Создайте папку images в корневой директории сервера и поместите туда все SVG-файлы изображений (spring-boot.svg, spring-framework.svg и т.д.).
Убедитесь, что сервер запускается без ошибок и выводит Server is running on port 5000.
Запустите клиентское приложение:
npm start
Убедитесь, что приложение корректно отображает карточки и поиск работает.
Примечания:
Кросс-доменные запросы (CORS): Так как сервер и клиентское приложение работают на разных портах, убедитесь, что у вас настроен CORS на сервере (вы уже используете cors() в index.js).
Пути к изображениям: Убедитесь, что пути к изображениям корректны и картинки доступны по указанным URL. Если изображения не отображаются, проверьте, что они раздаются правильно сервером и что пути указаны верно в projects.js.
Обработка ошибок: Мы добавили обработку ошибок при запросе данных с сервера. Вы можете улучшить пользовательский интерфейс, добавив более информативные сообщения об ошибках.
Заключение
Теперь ваше приложение будет получать список карточек с сервера, а поиск будет осуществляться на серверной стороне, возвращая только те карточки, которые соответствуют запросу. Это улучшит производительность приложения, особенно при большом количестве данных, и позволит поддерживать данные актуальными на сервере.