2020-10-31 13:33:59 -07:00
|
|
|
import express from 'express';
|
|
|
|
import authenticate from '../src/authenticate';
|
|
|
|
import dbConnection from './db';
|
2020-11-02 10:31:05 -08:00
|
|
|
import session from 'express-session';
|
|
|
|
import cookieParser from 'cookie-parser';
|
|
|
|
import grant from "grant";
|
|
|
|
import router from "./routes/user";
|
2020-11-10 14:41:56 -08:00
|
|
|
import { loadSuml } from './loader';
|
2020-10-31 13:33:59 -07:00
|
|
|
|
|
|
|
const app = express()
|
|
|
|
|
|
|
|
app.use(express.json());
|
|
|
|
app.use(express.urlencoded({ extended: true }));
|
2020-11-02 10:31:05 -08:00
|
|
|
app.use(cookieParser());
|
|
|
|
app.use(session({
|
|
|
|
secret: process.env.SECRET,
|
2020-11-02 11:16:08 -08:00
|
|
|
cookie: {},
|
2020-11-14 22:15:37 -08:00
|
|
|
resave: false,
|
|
|
|
saveUninitialized: false,
|
2020-11-02 10:31:05 -08:00
|
|
|
}));
|
2020-10-31 13:33:59 -07:00
|
|
|
|
|
|
|
app.use(async function (req, res, next) {
|
2020-11-10 14:41:56 -08:00
|
|
|
req.config = loadSuml('config');
|
2020-10-31 13:33:59 -07:00
|
|
|
req.rawUser = authenticate(req);
|
|
|
|
req.user = req.rawUser && req.rawUser.authenticated ? req.rawUser : null;
|
|
|
|
req.admin = req.user && req.user.roles === 'admin';
|
|
|
|
req.db = await dbConnection();
|
|
|
|
next();
|
2020-11-02 10:31:05 -08:00
|
|
|
});
|
|
|
|
|
2020-11-02 12:45:45 -08:00
|
|
|
router.use(grant.express()(require('./social').config));
|
2020-10-31 13:33:59 -07:00
|
|
|
|
|
|
|
app.use(require('./routes/banner').default);
|
|
|
|
|
|
|
|
app.use(require('./routes/user').default);
|
|
|
|
app.use(require('./routes/profile').default);
|
|
|
|
app.use(require('./routes/admin').default);
|
|
|
|
|
2020-11-10 15:47:44 -08:00
|
|
|
app.use(require('./routes/pronouns').default);
|
2020-10-31 13:33:59 -07:00
|
|
|
app.use(require('./routes/sources').default);
|
2020-11-10 14:41:56 -08:00
|
|
|
app.use(require('./routes/nouns').default);
|
2020-10-31 13:33:59 -07:00
|
|
|
|
|
|
|
export default {
|
|
|
|
path: '/api',
|
|
|
|
handler: app,
|
|
|
|
}
|