Skip to content

Commit 0d71075

Browse files
committed
added NotFound page for undefined paths, fix callback link to BE
1 parent 6258850 commit 0d71075

File tree

5 files changed

+29
-9
lines changed

5 files changed

+29
-9
lines changed

.DS_Store

0 Bytes
Binary file not shown.

server/routes/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { config } from 'dotenv';
1717
import log from '../logger/index';
1818
import type { DefaultErr } from '../../src/Types';
1919
import session from 'express-session';
20+
import path from 'path';
2021

2122
config();
2223

@@ -110,8 +111,9 @@ const routes = (app: Express) => {
110111
res.json({ message: 'Reached /api/ route' });
111112
});
112113

113-
app.get('/*', (_req, res) => {
114-
res.status(404).send('Not found');
114+
// This must be placed **after** all your API routes
115+
app.get('*', (_req, res) => {
116+
res.sendFile(path.join(__dirname, '../dist', 'index.html'));
115117
});
116118

117119
// Global Error Handler

src/App.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Shared from './pages/Shared';
88
import TestNewQuery from './pages/TestNewQuery';
99
import ViewSavedQueries from './pages/ViewSavedQueries';
1010
import GitHubCallback from './pages/GitHubCallback';
11+
import NotFound from './pages/NotFound';
1112

1213
//-- used to store and access login info. using Zustand (state management library)
1314
import useCredentialsStore from './store/credentialsStore';
@@ -51,6 +52,9 @@ const App: React.FC = () => {
5152
<Route path="/auth/github/callback" element={<GitHubCallback />} />
5253

5354
{/* main dashboard? route does not live inside the Shared layout */}
55+
56+
{/* Catch all route for undefined paths */}
57+
<Route path="*" element={<NotFound />} />
5458
</Routes>
5559
</BrowserRouter>
5660
);

src/pages/GitHubCallback.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@ import React from 'react';
22
import { useEffect } from 'react';
33
import { useNavigate } from 'react-router-dom';
44
import useCredentialsStore from '../store/credentialsStore';
5-
import { config } from 'dotenv';
6-
7-
config();
85

96
const GitHubCallback: React.FC = () => {
10-
const apiOauth = process.env.PROD_API_OAUTH || 'http://localhost:8080/api/oauth';
117
const setUser = useCredentialsStore((state) => state.setUser);
128
const navigate = useNavigate();
139

@@ -21,9 +17,9 @@ const GitHubCallback: React.FC = () => {
2117
return;
2218
}
2319

24-
// in development mode, change redirect_uri to 'http://localhost:8080/auth/github/callback'
25-
// in production mode, change redirect_uri back to 'https://dbspy.net/auth/github/callback' before deploying
26-
fetch('https://www.dbspy.net/auth/github/callback', {
20+
// in development mode, change redirect_uri to 'http://localhost:8080/api/oauth'
21+
// in production mode, change redirect_uri back to 'https://www.dbspy.net/api/oauth' before deploying
22+
fetch('https://www.dbspy.net/api/oauth', {
2723
method: 'POST',
2824
headers: { 'Content-Type': 'application/json' },
2925
body: JSON.stringify({ code, state, type: 'GITHUB' }),

src/pages/NotFound.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from 'react';
2+
import { Link } from 'react-router-dom';
3+
4+
const NotFound: React.FC = () => {
5+
return (
6+
<div style={{ textAlign: 'center', marginTop: '5rem' }}>
7+
<h1>404 - Page Not Found</h1>
8+
<p>The page you're looking for doesn't exist.</p>
9+
<p>
10+
<Link className="text-blue-600 dark:text-[#f8f4eb]" to="/">
11+
Return to homepage
12+
</Link>
13+
</p>
14+
</div>
15+
);
16+
};
17+
18+
export default NotFound;

0 commit comments

Comments
 (0)