const express = require('express');
const router = express.Router();

import { Request, Response } from 'express';
import { requireLogin } from '../middleware/auth';

router.get('/welcome', [requireLogin], async (req: Request, res: Response) => {
    const output = await fetch(`${process.env.DOC_HOST}/api/pages/717`, {
        headers: {
            Authorization: `Token ${process.env.DOC_TOKEN_ID}:${process.env.DOC_TOKEN_SECRET}`,
        }
    })

    if (output.ok) {
        const out = await output.json();
        res.status(200).json(out.html);
    } else {
        console.error("Failed to fetch LOA policy from bookstack");
        res.sendStatus(500);
    }
})


export const docsRouter = router;