/**
 * This file was automatically generated by openapi-codegeneration.
 * DO NOT MODIFY IT BY HAND. Instead, modify the source OpenAPI file,
 * and run openapi-codegeneration to regenerate this file.
 */
import express from "express";
import bodyParser from "body-parser";
import router from "./routes.js";
export const app = express();
// default error handler
const defaultErrorHandler = (err, req, res, _next) => {
    const status = err.status || 500;
    const message = err.error || err.message;
    const error = err.name || "Error";
    console.error(`${error} ${status} "${message}" on ${req.method} ${req.url}.`);
    res.status(status).send({ error, message });
};
app.initService = (options) => {
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: false }));
    // add pre handlers
    for (const handler of options.preHandlers ?? []) {
        handler(app);
    }
    // add routes
    app.use("/", router());
    // add post handlers
    for (const handler of options.postHandlers ?? []) {
        handler(app);
    }
    app.use(options.errorHandler ?? defaultErrorHandler);
};
//# sourceMappingURL=index.js.map