Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 7 additions & 36 deletions backend/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,14 @@
// backend/routes/index.js
const express = require('express');
const router = express.Router();

const apiRouter = require('./api');

router.use('/api', apiRouter);

// Static routes
// Serve React build files in production
if (process.env.NODE_ENV === "production") {
const path = require("path");
// Serve the frontend's index.html file at the root route
router.get("/", (req, res) => {
res.cookie("XSRF-TOKEN", req.csrfToken());
return res.sendFile(
path.resolve(__dirname, "../../frontend", "build", "index.html")
);
})

// Serve the static assets in the frontend's build folder
router.use(express.static(path.resolve("../frontend/build")));

// Serve the frontend's index.html file at all other routes NOT starting with /api
router.get(/^(?!\/?api).*/, (req, res) => {
res.cookie("XSRF-TOKEN", req.csrfToken());
res.sendFile(
path.resolve(__dirname, "../../frontend", "build", "index.html")
);
})
}

// Add a XSRF-TOKEN cookie in development
if (process.env.NODE_ENV !== "production") {
router.get("/api/csrf/restore", (req, res) => {
res.cookie("XSRF-TOKEN", req.csrfToken());
return res.json({});
})
}

// for testing purposes
// router.get('/hello/world', function(req, res) {
// res.cookie('XSRF-TOKEN', req.csrfToken());
// res.send('Hello World!');
// router.get('/hello/world', function (req, res) {
// res.cookie('XSRF-TOKEN', req.csrfToken());
// res.send('Hello World!');
// });

// Add a XSRF-TOKEN cookie
Expand All @@ -50,5 +19,7 @@ router.get("/api/csrf/restore", (req, res) => {
'XSRF-Token': csrfToken
});
});
// ...


module.exports = router;
3 changes: 1 addition & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,5 @@
},
"devDependencies": {
"redux-logger": "^3.0.6"
},
"proxy": "http://localhost:8000"
}
}
25 changes: 2 additions & 23 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,6 @@
// frontend/src/App.js
import React, { useState, useEffect } from "react";
import { useDispatch } from "react-redux";
import { Route, Switch } from "react-router-dom";
import LoginFormPage from "./components/LoginFormPage";
import SignupFormPage from "./components/SignupFormPage";
import * as sessionActions from "./store/session";

function App() {
const dispatch = useDispatch();
const [isLoaded, setIsLoaded] = useState(false);
useEffect(() => {
dispatch(sessionActions.restoreUser()).then(() => setIsLoaded(true));
}, [dispatch]);

return isLoaded && (
<Switch>
<Route path="/login">
<LoginFormPage />
</Route>
<Route path="/signup">
<SignupFormPage />
</Route>
</Switch>
return (
<h1>Hello from App</h1>
);
}

Expand Down
Empty file.
57 changes: 0 additions & 57 deletions frontend/src/components/LoginFormPage/index.js

This file was deleted.

Empty file.
98 changes: 0 additions & 98 deletions frontend/src/components/SignupFormPage/index.js

This file was deleted.

8 changes: 1 addition & 7 deletions frontend/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@ import { Provider as ReduxProvider } from 'react-redux';
import './index.css';
import App from './App';
import configureStore from './store';
import { restoreCSRF, csrfFetch } from './store/csrf';
import * as sessionActions from './store/session';

const store = configureStore();

if (process.env.NODE_ENV !== 'production') {
restoreCSRF();

window.csrfFetch = csrfFetch;
if (process.env.NODE_ENV !== "production") {
window.store = store;
window.sessionActions = sessionActions;
}

function Root() {
Expand Down
31 changes: 0 additions & 31 deletions frontend/src/store/csrf.js

This file was deleted.

2 changes: 0 additions & 2 deletions frontend/src/store/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { createStore, combineReducers, applyMiddleware, compose } from "redux";
import thunk from "redux-thunk";
import sessionReducer from './session';

const rootReducer = combineReducers({
// add reducer functions here
session: sessionReducer,
});

let enhancer;
Expand Down
80 changes: 0 additions & 80 deletions frontend/src/store/session.js

This file was deleted.