You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.0 KiB

3 years ago
  1. import 'dotenv/config';
  2. import './db';
  3. import express from 'express';
  4. import { authRouter } from './auth';
  5. import bodyParser from 'body-parser';
  6. import session from 'express-session';
  7. import passport from 'passport';
  8. const app = express();
  9. const port = process.env.PORT || 3000;
  10. app.use(
  11. session({
  12. secret: process.env.SESSION_SECRET!,
  13. resave: false,
  14. saveUninitialized: false,
  15. cookie: {
  16. secure: process.env.NODE_ENV === 'production',
  17. },
  18. //store: MongoStore.create({ mongoUrl: uri, ttl: 24 * 60 * 60 }),
  19. })
  20. );
  21. app.disable('X-Powered-By');
  22. if (process.env.NODE_ENV === 'production') app.set('trust proxy', 1);
  23. app.use(express.json());
  24. app.use(bodyParser.urlencoded({ extended: false }));
  25. app.use(passport.initialize());
  26. app.use(passport.session());
  27. app.use(bodyParser.json());
  28. app.use('/auth', authRouter);
  29. app.get('/', (req, res) => {
  30. const u = req.user as any;
  31. if (u) {
  32. res.send(`Logged in as ${u.username}`);
  33. } else {
  34. res.send('Not logged in!');
  35. }
  36. });
  37. app.listen(port, () => {
  38. console.log(`Running Server at port ${port}`);
  39. });