"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.wellKnownRouter = void 0;
const tslib_1 = require("tslib");
const cors_1 = tslib_1.__importDefault(require("cors"));
const express_1 = tslib_1.__importDefault(require("express"));
const path_1 = require("path");
const core_utils_1 = require("../../shared/core-utils");
const config_1 = require("../initializers/config");
const constants_1 = require("../initializers/constants");
const cache_1 = require("../middlewares/cache/cache");
const middlewares_1 = require("../middlewares");
const wellKnownRouter = express_1.default.Router();
exports.wellKnownRouter = wellKnownRouter;
wellKnownRouter.use((0, cors_1.default)());
wellKnownRouter.get('/.well-known/security.txt', (0, cache_1.cacheRoute)(constants_1.ROUTE_CACHE_LIFETIME.SECURITYTXT), (_, res) => {
    res.type('text/plain');
    return res.send(config_1.CONFIG.INSTANCE.SECURITYTXT + config_1.CONFIG.INSTANCE.SECURITYTXT_CONTACT);
});
wellKnownRouter.use('/.well-known/nodeinfo', (0, cache_1.cacheRoute)(constants_1.ROUTE_CACHE_LIFETIME.NODEINFO), (_, res) => {
    return res.json({
        links: [
            {
                rel: 'http://nodeinfo.diaspora.software/ns/schema/2.0',
                href: constants_1.WEBSERVER.URL + '/nodeinfo/2.0.json'
            }
        ]
    });
});
wellKnownRouter.use('/.well-known/dnt-policy.txt', (0, cache_1.cacheRoute)(constants_1.ROUTE_CACHE_LIFETIME.DNT_POLICY), (_, res) => {
    res.type('text/plain');
    return res.sendFile((0, path_1.join)((0, core_utils_1.root)(), 'dist/server/static/dnt-policy/dnt-policy-1.0.txt'));
});
wellKnownRouter.use('/.well-known/dnt/', (_, res) => {
    res.json({ tracking: 'N' });
});
wellKnownRouter.use('/.well-known/change-password', (_, res) => {
    res.redirect('/my-account/settings');
});
wellKnownRouter.use('/.well-known/host-meta', (_, res) => {
    res.type('application/xml');
    const xml = '<?xml version="1.0" encoding="UTF-8"?>\n' +
        '<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">\n' +
        `  <Link rel="lrdd" type="application/xrd+xml" template="${constants_1.WEBSERVER.URL}/.well-known/webfinger?resource={uri}"/>\n` +
        '</XRD>';
    res.send(xml).end();
});
wellKnownRouter.use('/.well-known/', (0, cache_1.cacheRoute)(constants_1.ROUTE_CACHE_LIFETIME.WELL_KNOWN), express_1.default.static(config_1.CONFIG.STORAGE.WELL_KNOWN_DIR, { fallthrough: false }), middlewares_1.handleStaticError);
//# sourceMappingURL=well-known.js.map