"use strict";
/**
 * Copyright 2020 Baidu Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const io_1 = __importDefault(require("./builder/io"));
const meta_json_1 = __importDefault(require("./data/meta.json"));
const path_1 = __importDefault(require("path"));
function notFound(res) {
    res.status(404).send({
        status: 1,
        msg: 'Not found'
    });
}
exports.default = async (req, res) => {
    const method = req.path;
    if (!method) {
        return notFound(res);
    }
    const data = meta_json_1.default.find(item => io_1.default.isSameUri(item, { uri: method, query: req.query }));
    if (!data) {
        return notFound(res);
    }
    res.sendFile(path_1.default.join(__dirname, 'data/data', data.uri, data.filename), {
        headers: data.headers
    });
};
