import "./utils/env"
import express, { Request, Response, NextFunction, Application } from "express";
import bodyParser from "body-parser";
import expressSession from "express-session";

const app: Application = express();

app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
app.use(expressSession({
  secret: process.env.SESSION_SECRET || "alma",
  resave: false,
  saveUninitialized: true,
  cookie: { secure: true }
}));
app.get("/", (req: Request, res: Response) => res.send("Hel World!"));

// Register routes


app.use((err: any, req: Request, res: Response, next: NextFunction) => {
  res.status(500).send("Houston, we have a problem!");

  //Flush out the stack to the console
  console.error(err.stack);
});

app.listen(8000, () => console.log(`Example app listening on port 8000!`));