Add api proxy

This commit is contained in:
= 2024-12-06 02:50:16 +01:00
parent 2adacceac5
commit e2261f829c
3 changed files with 43 additions and 11 deletions

View file

@ -1,5 +1,7 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { useParams } from 'react-router-dom'; import { useParams } from 'react-router-dom';
import NavBar from '../components/NavBar';
import Footer from '../components/Footer';
interface Article { interface Article {
id: string; id: string;
@ -7,6 +9,7 @@ interface Article {
content: string; content: string;
author: string; author: string;
publishedAt: string; publishedAt: string;
editedAt: string;
} }
const ArticlePage: React.FC = () => { const ArticlePage: React.FC = () => {
@ -36,17 +39,38 @@ const ArticlePage: React.FC = () => {
} }
return ( return (
<div> <div style={{
display: 'flex',
flexDirection: 'column',
minHeight: '100vh'
}}>
<NavBar/>
<div style={{
borderRadius: '8px',
color: 'var(--color-black)',
fontFamily: '"Haas Grot Text R Web", "Helvetica Neue", Helvetica, Arial, sans-serif',
fontSize: '14px',
lineHeight: '20px',
padding: '1.25em',
paddingBottom: '1em',
textAlign: 'left',
maxWidth: '60rem',
margin: 'auto',
}}>
<img src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fimages8.alphacoders.com%2F438%2F438396.jpg&f=1&nofb=1&ipt=14796576c139b58db62d2d2098392ef2fbaee77911040f7c0d98ab65a69c4644&ipo=images" alt="Article preview" style={{ <img src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fimages8.alphacoders.com%2F438%2F438396.jpg&f=1&nofb=1&ipt=14796576c139b58db62d2d2098392ef2fbaee77911040f7c0d98ab65a69c4644&ipo=images" alt="Article preview" style={{
borderRadius: '8px', borderRadius: '8px',
width: '100%', width: '100%',
height: 'auto', height: 'auto',
marginBottom: '10px', marginBottom: '10px',
}} /> }} />
<div>
<h1>{article.title}</h1> <h1>{article.title}</h1>
<p>écrit par {article.author} le {new Date(article.publishedAt).toLocaleDateString()} (Dernière modification le : {new Date(article.editedAt || article.publishedAt).toLocaleDateString()})</p>
<hr/>
<p>{article.content}</p> <p>{article.content}</p>
<p>By {article.author}</p> </div>
<p>Published on {new Date(article.publishedAt).toLocaleDateString()}</p> </div>
<Footer bgcolor='lightblue'/>
</div> </div>
); );
}; };

View file

@ -11,7 +11,6 @@ export default function MainPage() {
txtbt1="Un" txtbt1="Un"
txtbt2="Deux" txtbt2="Deux"
image="url('/pictures/sea.gif')"/> image="url('/pictures/sea.gif')"/>
<div style={{height:"30px"}} />
<ArticlesSection /> <ArticlesSection />
<Footer bgcolor="lightblue"/> <Footer bgcolor="lightblue"/>
</div> </div>

View file

@ -4,4 +4,13 @@ import react from '@vitejs/plugin-react'
// https://vite.dev/config/ // https://vite.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [react()], plugins: [react()],
server: {
proxy: {
'/api': {
target: 'http://localhost:2486',
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, '')
}
}
}
}) })