"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const express = require("express");
const sdk_1 = require("@directus/sdk");
const events_1 = require("../events");
async function default_1(config, opts = {}) {
    config.on(events_1.EVENT_STARTUP_START, ({ app }) => {
        const router = express.Router();
        router.post('/publish', async function (req, res, next) {
            try {
                const token = req.body.token;
                const directus = new sdk_1.Directus(opts.directusUrl);
                directus.storage.auth_token = token;
                const me = await directus.users.me.read();
                next();
            }
            catch (err) {
                console.error('Publish failed', err.message);
                res.status(403).json({ message: err.message });
            }
        });
        app.use(router);
    });
}
exports.default = default_1;
