Skip to content

Commit a55cbeb

Browse files
committed
Handle redirects w/o Nginx
1 parent 1d4a5f4 commit a55cbeb

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

client/src/components/App.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { BrowserRouter, Route, Routes } from 'react-router-dom';
55
import Header from './header/Header';
66
import Home from './home/Home';
77
import Footer from './footer/Footer';
8+
import RedirectToApi from './redirect/redirect';
89

910
import './styles.css';
1011

@@ -15,6 +16,7 @@ const App = () => (
1516
<Header />
1617
<Routes>
1718
<Route path="/" element={<Home />} />
19+
<Route path="*" element={<RedirectToApi />} />
1820
</Routes>
1921
<Footer />
2022
</div>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React, { useEffect } from 'react';
2+
3+
function RedirectToApi() {
4+
useEffect(() => {
5+
const currentPath = window.location.pathname;
6+
7+
// If the path matches your desired pattern, redirect to the API
8+
if (/^[0-9a-z!?@_-]{1,99}$/.test(currentPath.slice(1))) {
9+
window.location.href = `https://yo-api.fairbanks.dev/api/link${currentPath}`;
10+
} else {
11+
// Handle non-matching routes, e.g., show a 404 page
12+
window.location.href = '/';
13+
}
14+
}, []);
15+
16+
return <div>Yo dawg...</div>;
17+
}
18+
19+
export default RedirectToApi;

0 commit comments

Comments
 (0)