From b209293dd88bde996d895ec01e030667fb4ec16a Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Wed, 4 Jan 2023 13:20:42 -0500 Subject: [PATCH] all the ham --- App.js | 22 ++++++++++++++++++++++ server.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 App.js create mode 100644 server.js diff --git a/App.js b/App.js new file mode 100644 index 0000000..3368aaf --- /dev/null +++ b/App.js @@ -0,0 +1,22 @@ +import axios from 'axios'; + +const App = () => { + const createSession = (event)=>{ + event.preventDefault(); + axios.post('http://localhost:3000', {}, {withCredentials:true}).then((response)=>{ + console.log(response); + }) + } + const getSession = (event)=>{ + event.preventDefault(); + axios.get('http://localhost:3000', {withCredentials:true}).then((response)=>{ + console.log(response); + }) + } + return <> + + + +} + +export default App; diff --git a/server.js b/server.js new file mode 100644 index 0000000..31dbb92 --- /dev/null +++ b/server.js @@ -0,0 +1,29 @@ +const express = require('express') +const cors = require('cors') +const session = require('express-session') +const app = express() + +app.use(cors( + { + origin:'http://localhost:3001', + credentials:true + } +)) +app.use( + session({ + secret: 'feedmeseymour', //a random string do not copy this value or your stuff will get hacked + resave: false, // default more info: https://www.npmjs.com/package/express-session#resave + saveUninitialized: false // default more info: https://www.npmjs.com/package/express-session#resave + }) +) + +app.get('/', (req, res)=>{ + res.send(req.session.currentUser) +}) + +app.post('/', (req, res)=>{ + req.session.currentUser = "bob" + res.send(req.session.currentUser) +}) + +app.listen(3000)