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

import 'dotenv/config';
import './db';
import express from 'express';
import { authRouter } from './auth';
import bodyParser from 'body-parser';
import session from 'express-session';
import passport from 'passport';
const app = express();
const port = process.env.PORT || 3000;
app.use(
session({
secret: process.env.SESSION_SECRET!,
resave: false,
saveUninitialized: false,
cookie: {
secure: process.env.NODE_ENV === 'production',
},
//store: MongoStore.create({ mongoUrl: uri, ttl: 24 * 60 * 60 }),
})
);
app.disable('X-Powered-By');
if (process.env.NODE_ENV === 'production') app.set('trust proxy', 1);
app.use(express.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(passport.initialize());
app.use(passport.session());
app.use(bodyParser.json());
app.use('/auth', authRouter);
app.get('/', (req, res) => {
const u = req.user as any;
if (u) {
res.send(`Logged in as ${u.username}`);
} else {
res.send('Not logged in!');
}
});
app.listen(port, () => {
console.log(`Running Server at port ${port}`);
});