const express = require("express");
const cors = require("cors");
const session = require("express-session");

const app = express();
app.use(
  cors({
    origin: "http://localhost:3000",
    credentials: true,
  })
);
app.use(session({ secret: "keyboard cat", cookie: {} }));

const port = 3001;

app.get("/", (req, res) => {
  res.send("Hello World!");
});

app.get("/write_session", (req, res) => {
  req.session.hello = "world";
  console.log(req.session);
  res.send({ msg: "hello write!" });
});

app.get("/read_session", (req, res) => {
  console.log(req.session);
  res.send({ msg: "Hello read!" });
});

app.get("/hello_json", (req, res) => {
  res.send({ hello: "world" });
});

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`);
});
