commit
b209293dd8
@ -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 <>
|
||||
<button onClick={createSession}>Create Session</button>
|
||||
<button onClick={getSession}>Get Session Info</button>
|
||||
</>
|
||||
}
|
||||
|
||||
export default App;
|
||||
@ -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)
|
||||
Loading…
Reference in new issue