summaryrefslogtreecommitdiffstats
path: root/server/src/srv.cpp
blob: 287f83841a56c363c7a21728c8d7b2548b006561 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
module;

#include <boost/asio/as_tuple.hpp>
#include <boost/asio/awaitable.hpp>
#include <boost/asio/co_spawn.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/beast/core.hpp>
#include <boost/beast/http.hpp>
#include <boost/beast/zlib.hpp>
#include <boost/config.hpp>
#include <boost/json.hpp>
#include <boost/locale/generator.hpp>

#include <expat.h>

#include <openssl/crypto.h>

module routemon:srv$impl;

import std;
import :gpx;
import :srv;
import :rwgps.webhook;

namespace beast = boost::beast;
namespace chrono = std::chrono;
namespace json = boost::json;
namespace net = boost::asio;
using tcp = boost::asio::ip::tcp;

namespace routemon::srv {

class gpx_parse_error_category_impl : public std::error_category
{
public:
  auto name() const noexcept -> char const* override { return "gpx_parse"; }

  auto message(int condition) const noexcept -> std::string override
  {
    std::ignore = condition;
    return "failed to parse GPX file";
  }
};

auto gpx_parse_error_category() noexcept -> gpx_parse_error_category_impl const&
{
  static auto const inst = gpx_parse_error_category_impl{};
  return inst;
}

auto gpx_parse_error() noexcept -> std::error_code
{
  return std::error_code{1, gpx_parse_error_category()};
}

class gpx_parse_result
{
  chrono::steady_clock::duration init_parse_dur_;
  chrono::steady_clock::duration put_parse_dur_;
  chrono::steady_clock::duration finish_parse_dur_;
  std::variant<std::exception_ptr, gpx::file> res_;

public:
  auto set_exception(std::exception_ptr ex) noexcept { res_ = ex; }
  auto set_gpx_file(gpx::file&& f) noexcept { res_ = std::move(f); }

  auto init_parse_duration(chrono::steady_clock::duration dur) noexcept
  {
    init_parse_dur_ = dur;
  }
  [[nodiscard]] auto init_parse_duration() const noexcept
      -> chrono::steady_clock::duration
  {
    return init_parse_dur_;
  }
  auto put_parse_duration(chrono::steady_clock::duration dur) noexcept
  {
    put_parse_dur_ = dur;
  }
  [[nodiscard]] auto put_parse_duration() const noexcept
      -> chrono::steady_clock::duration
  {
    return put_parse_dur_;
  }
  auto finish_parse_duration(chrono::steady_clock::duration dur) noexcept
  {
    finish_parse_dur_ = dur;
  }
  [[nodiscard]] auto finish_parse_duration() const noexcept
      -> chrono::steady_clock::duration
  {
    return finish_parse_dur_;
  }

  auto unwrap() -> gpx::file&&
  {
    return std::visit(
        util::overloaded{
          [](std::exception_ptr ex) -> gpx::file&&
          {
            if (ex)
              std::rethrow_exception(ex);
            else
              throw std::runtime_error{"no GPX file parse result available"};
          },
          [](gpx::file&& f) -> gpx::file&& { return std::move(f); },
        },
        std::move(res_));
  }
};

struct readable_gpx_body
{
  using value_type = gpx_parse_result;

  class reader
  {
    gpx::reader r_;
    util::not_null<value_type*> res_;
    std::inplace_vector<char, 4096> buf_;

  public:
    template <bool isRequest, bhttp::concepts::fields Fields>
    explicit reader(bhttp::header<isRequest, Fields>&, value_type& v) : res_{&v}
    {
      res_->init_parse_duration({});
      res_->put_parse_duration({});
      res_->finish_parse_duration({});
    }

    // The following methods (which are called by Beast) are marked
    // noexcept, since Beast does not ensure that exceptions thrown
    // here are appropriately directed to the caller of
    // (async_)read(_some), so throwing here might cause the program
    // to crash.

    auto
    init(boost::optional<std::uint64_t> /* n */, beast::error_code& ec) noexcept
        -> void
    {
      auto const init_start = chrono::steady_clock::now();
      try
      {
        r_.init();
        ec = {};
      }
      catch (std::exception& ex)
      {
        res_->set_exception(std::current_exception());
        ec = gpx_parse_error();
      }
      res_->init_parse_duration(chrono::steady_clock::now() - init_start);
    }

    auto
    put(beast::concepts::const_buffer_sequence auto b,
        beast::error_code& ec) noexcept -> std::size_t
    {
      auto const put_start = chrono::steady_clock::now();
      auto total = 0uz;
      try
      {
        for (auto cur_in_buf : beast::buffers_range(b))
        {
          while (cur_in_buf.size() > 0)
          {
            auto to_read =
                std::min(cur_in_buf.size(), buf_.max_size() - buf_.size());
            buf_.append_range(
                std::span{
                  static_cast<char const*>(cur_in_buf.data()), to_read
                });
            cur_in_buf += to_read;
            total += to_read;

            if (buf_.size() == buf_.max_size())
            {
              r_.put(std::string_view{buf_});
              buf_.clear();
            }
          }
        }
        ec = {};
      }
      catch (std::exception& ex)
      {
        res_->set_exception(std::current_exception());
        ec = gpx_parse_error();
      }
      res_->put_parse_duration(
          res_->put_parse_duration()
          + (chrono::steady_clock::now() - put_start));
      return total;
    }

    auto finish(beast::error_code& ec) noexcept
    {
      auto const finish_start = chrono::steady_clock::now();
      try
      {
        if (buf_.size() > 0)
        {
          r_.put(std::string_view{buf_});
          buf_.clear();
        }

        res_->set_gpx_file(r_.finish());
        ec = {};
      }
      catch (std::exception& ex)
      {
        res_->set_exception(std::current_exception());
        ec = gpx_parse_error();
      }
      res_->finish_parse_duration(chrono::steady_clock::now() - finish_start);
    }
  };
};
static_assert(bhttp::concepts::body<readable_gpx_body>);
static_assert(bhttp::concepts::body_reader<readable_gpx_body>);

template <bhttp::concepts::body_reader Inner>
struct raw_deflate_body
{
  using value_type = Inner::value_type;

  class reader
  {
    static constexpr auto const chunk_size = 16384;

    Inner::reader r_;
    bool stream_ended_ = false;
    beast::zlib::z_params zs_ = {};
    beast::zlib::inflate_stream inflate_strm_ = {};
    std::unique_ptr<std::array<char, chunk_size>> in_buf_ = nullptr;
    std::unique_ptr<std::array<char, chunk_size>> out_buf_ = nullptr;

    auto inflate_chunk(beast::error_code& ec) -> void
    {
      assert(zs_.avail_in > 0);
      zs_.next_in = in_buf_->data();

      do
      {
        zs_.avail_out = out_buf_->size();
        zs_.next_out = out_buf_->data();

        inflate_strm_.write(zs_, beast::zlib::Flush::none, ec);
        assert(ec != beast::zlib::error::stream_error);
        if (ec == beast::zlib::error::need_buffers)
          ec = {};
        if (ec == beast::zlib::error::end_of_stream)
        {
          ec = {};
          stream_ended_ = true;
        }
        if (ec)
          break;

        auto have = chunk_size - zs_.avail_out;
        auto cbuf =
            net::buffer(static_cast<void const*>(out_buf_->data()), have);

        auto inner_ec = beast::error_code{};
        do
          cbuf += r_.put(cbuf, inner_ec);
        while (cbuf.size() > 0 && !inner_ec);
        if (inner_ec)
        {
          ec = inner_ec;
          break;
        }
      }
      while (zs_.avail_out == 0);

      // In the last case (stream_ended_), the user has sent too much data
      assert(zs_.avail_in == 0 || ec || stream_ended_);
    }

  public:
    template <bool isRequest, bhttp::concepts::fields Fields>
    explicit reader(bhttp::header<isRequest, Fields>& hdr, value_type& v)
      : r_{hdr, v}
    {
    }

    auto
    init(boost::optional<std::uint64_t> /* n */, beast::error_code& ec) noexcept
        -> void
    {
      in_buf_.reset(new std::array<char, chunk_size>{});
      out_buf_.reset(new std::array<char, chunk_size>{});
      ec = {};
    }

    auto
    put(beast::concepts::const_buffer_sequence auto b,
        beast::error_code& ec) noexcept -> std::size_t
    {
      auto in_buf = net::buffer(in_buf_->data(), in_buf_->size());
      in_buf += zs_.avail_in;

      auto consumed_from_b = net::buffer_copy(in_buf, b);
      zs_.avail_in += consumed_from_b;

      if (zs_.avail_in == in_buf_->size())
        inflate_chunk(ec);
      else
        ec = {};

      return consumed_from_b;
    }

    auto finish(beast::error_code& ec) noexcept
    {
      ec = {};
      if (zs_.avail_in > 0)
        inflate_chunk(ec);
      if (!ec && !stream_ended_)
        ec = beast::zlib::error::stream_error;
      if (stream_ended_ && zs_.avail_in > 0)
        // client sent data past deflate stream end
        ec = beast::zlib::error::stream_error;

      in_buf_.reset();
      out_buf_.reset();
      inflate_strm_.reset();
      if (!ec)
      {
        r_.finish(ec);
      }
    }
  };
};

auto parse_timestamp_mins(std::string_view in)
    -> std::optional<time::timestamp<std::chrono::minutes>>
{
  auto res = time::timestamp<std::chrono::minutes>{};
  auto is = std::istringstream{in};
  is >> std::chrono::parse("%Y-%m-%dT%H:%MZ", res);
  return is.fail() ? std::nullopt : std::make_optional(res);
}

auto handler::handle_process_gpx(l0_ctx ctx, http::readable_request r)
    -> net::awaitable<http::presponse>
{
  auto l =
      l_.sub("handle_process_gpx").with("trace_id", ctx.trace_id.as_string());

  auto cp_begin = time::timestamp<std::chrono::minutes>{};
  auto cp_end = time::timestamp<std::chrono::minutes>{};

  auto const params = ctx.target.params();
  if (auto it = params.find("cpbegin"); it != params.end())
  {
    auto mts = parse_timestamp_mins((*it).value);
    if (!mts)
    {
      auto tpl = problem::tpl{
        .status = bhttp::status::bad_request,
        .title = translate("Query parameter has bad value"),
        .type_uri =
            "https://routemon.fautchen.eu/problems/query-param-bad-value",
      };
      co_return http::problem_rsp(
          ctx, tpl.instantiate(), http::keep_alive{false});
    }
    cp_begin = *mts;

    ++it;
    if (it != params.end() && (*it).key == "cpbegin")
    {
      auto tpl = problem::tpl{
        .status = bhttp::status::bad_request,
        .title = translate("Query parameter provided too many times"),
        .type_uri = "https://routemon.fautchen.eu/problems/"
                    "query-param-too-many-occurrences",
      };
      co_return http::problem_rsp(
          ctx, tpl.instantiate(), http::keep_alive{false});
    }
  }
  else
  {
    auto tpl = problem::tpl{
      .status = bhttp::status::bad_request,
      .title = translate("Required query parameter not provided"),
      .type_uri = "https://routemon.fautchen.eu/problems/"
                  "required-query-param-not-provided",
    };
    co_return http::problem_rsp(
        ctx, tpl.instantiate(), http::keep_alive{false});
  }
  if (auto it = params.find("cpend"); it != params.end())
  {
    auto mts = parse_timestamp_mins((*it).value);
    if (!mts)
    {
      auto tpl = problem::tpl{
        .status = bhttp::status::bad_request,
        .title = translate("Query parameter has bad value"),
        .type_uri =
            "https://routemon.fautchen.eu/problems/query-param-bad-value",
      };
      co_return http::problem_rsp(
          ctx, tpl.instantiate(), http::keep_alive{false});
    }
    cp_end = *mts;

    ++it;
    if (it != params.end() && (*it).key == "cpend")
    {
      auto tpl = problem::tpl{
        .status = bhttp::status::bad_request,
        .title = translate("Query parameter provided too many times"),
        .type_uri = "https://routemon.fautchen.eu/problems/"
                    "query-param-too-many-occurrences",
      };
      co_return http::problem_rsp(
          ctx, tpl.instantiate(), http::keep_alive{false});
    }
  }
  else
  {
    auto tpl = problem::tpl{
      .status = bhttp::status::bad_request,
      .title = translate("Required query parameter not provided"),
      .type_uri = "https://routemon.fautchen.eu/problems/"
                  "required-query-param-not-provided",
    };
    co_return http::problem_rsp(
        ctx, tpl.instantiate(), http::keep_alive{false});
  }

  if (cp_begin >= cp_end)
  {
    auto tpl = problem::tpl{
      .status = bhttp::status::bad_request,
      .title = translate("Invalid check period provided"),
      .type_uri = "https://routemon.fautchen.eu/problems/invalid-check-period",
    };
    co_return http::problem_rsp(
        ctx,
        tpl.instantiate().set_detail(translate(
            "Begin of check period must be before end of check period")),
        http::keep_alive{false});
  }
  auto cp = time::period<std::chrono::minutes>{cp_begin, cp_end};

  auto gpx_file = gpx::file{};
  try
  {
    l.debug("Reading GPX request body");
    auto const before_read_gpx = chrono::steady_clock::now();
    auto parse_res =
        r.p->get()[bhttp::field::content_encoding] == "x-deflate-raw"
            ? std::move((co_await http::
                             read_request<raw_deflate_body<readable_gpx_body>>(
                                 ctx, std::move(r)))
                            .body())
            : std::move((co_await http::read_request<readable_gpx_body>(
                             ctx, std::move(r)))
                            .body());
    l.debug(
        "Read GPX request body in {}; init took {}, actual parsing {}, "
        "finishing {}",
        chrono::duration<double, std::milli>{
          chrono::steady_clock::now() - before_read_gpx
        },
        chrono::duration<double, std::milli>{parse_res.init_parse_duration()},
        chrono::duration<double, std::milli>{parse_res.put_parse_duration()},
        chrono::duration<double, std::milli>{
          parse_res.finish_parse_duration()
        });
    gpx_file = std::move(parse_res.unwrap());
  }
  catch (std::exception& ex)
  {
    l_.warn("Failed to parse GPX file: {}", ex.what());
    // TODO: more detailed problem reporting
    auto tpl = problem::tpl{
      .status = bhttp::status::bad_request,
      .title = translate("Failed to parse GPX file"),
      .type_uri = "https://routemon.fautchen.eu/problems/gpx-parse-failed",
    };
    co_return http::problem_rsp(
        ctx, tpl.instantiate(), http::keep_alive{false});
  }

  // TODO: catch handler exceptions and return 500 when raised?
  // (keep-alive depends on whether whole request was read)
  auto mres = inner_.process_gpx(
      ctx.trace_id, std::move(gpx_file),
      time::period_seq<std::chrono::minutes>{cp});
  if (!mres)
  {
    auto tpl = problem::tpl{
      .status = bhttp::status::internal_server_error,
      .title = translate("Internal server error"),
      .type_uri = "https://routemon.fautchen.eu/problems/"
                  "internal-server-error",
    };
    co_return http::problem_rsp(ctx, tpl.instantiate(), http::keep_alive{true});
  }

  auto rsp = http::make_rsp<bhttp::string_body>(
      bhttp::status::ok, http::keep_alive{true});
  rsp.set(bhttp::field::content_type, "application/json");
  rsp.body() = json::serialize(json::value_from(*mres));
  rsp.prepare_payload();
  co_return rsp;
}

auto handler::handle_sysinfo(l0_ctx ctx, http::readable_request r)
    -> net::awaitable<http::presponse>
{
  auto req = co_await http::read_empty_request(ctx, std::move(r));
  auto info = inner_.sysinfo();

  auto rsp = http::make_rsp<bhttp::string_body>(
      bhttp::status::ok, http::keep_alive{true});
  rsp.set(bhttp::field::content_type, "application/json");
  rsp.body() = json::serialize(json::value_from(info));
  rsp.prepare_payload();
  co_return rsp;
}

auto decode_hexnib(char c) -> std::optional<std::uint8_t>
{
  if ('a' <= c && c <= 'f')
    return c - 'a' + 10;
  if ('A' <= c && c <= 'F')
    return c - 'A' + 10;
  if ('0' <= c && c <= '9')
    return c - '0';
  return std::nullopt;
}

auto parse_timestamp_secs(std::string_view in)
    -> std::optional<time::timestamp<std::chrono::seconds>>
{
  auto res = time::timestamp<std::chrono::seconds>{};
  auto is = std::istringstream{in};
  is >> std::chrono::parse("%FT%TZ", res);
  return is.fail() ? std::nullopt : std::make_optional(res);
}

auto handler::handle_rwgps_webhook(l0_ctx ctx, http::readable_request r)
    -> net::awaitable<http::presponse>
{
  if (r.p->get()[bhttp::field::content_type] != "application/json")
  {
    // TODO: 415 Unsupported Media Type
    // (respond Accept-Post: application/json)
    throw std::runtime_error{"unhandled: unsupported media type provided"};
  }

  auto mrwgps_ts = parse_timestamp_secs(r.p->get()["x-rwgps-datetime"]);
  if (!mrwgps_ts)
  {
    // TODO: 400 Bad Request
    throw std::runtime_error{
      "failed to parse ISO 8601 date/time in x-rwgps-datetime header"
    };
  }

  // TODO: better to instead copy the expected API key to a buffer of
  // (at least) the size of the input API key and to compare those two
  // buffers? Then this operation should be Ω/Θ(API key provided in
  // request)
  auto req_api_key = r.p->get()["x-rwgps-api-key"];
  auto req_api_key_copy = std::string(rwgps_creds_->api_key().size(), 'X');
  std::memcpy(
      req_api_key_copy.data(), req_api_key.data(),
      std::min(req_api_key.size(), rwgps_creds_->api_key().size()));

  if (CRYPTO_memcmp(
          req_api_key_copy.data(), rwgps_creds_->api_key().data(),
          rwgps_creds_->api_key().size()))
  {
    // TODO: Unauthorized
    // TODO: constant-time comparison
    throw std::runtime_error{"unhandled: mismatching API key provided"};
  }

  auto rwgps_sig = r.p->get()["x-rwgps-signature"];
  auto rwgps_sig_decoded = std::array<std::uint8_t, 32>{};

  if (rwgps_sig.length() != 2 * rwgps_sig_decoded.size())
  {
    // TODO: Bad request
    throw std::runtime_error{"unhandled: bad signature provided"};
  }

  for (auto [i, b] : rwgps_sig_decoded | std::views::enumerate)
  {
    auto mhi = decode_hexnib(rwgps_sig[static_cast<std::size_t>(i) * 2]);
    auto mlo = decode_hexnib(rwgps_sig[static_cast<std::size_t>(i) * 2 + 1]);
    if (!mhi || !mlo)
    {
      throw std::runtime_error{"TODO: INVALID SIGNATURE"};
    }
    static_assert(std::same_as<decltype(b), std::uint8_t&>);
    b = static_cast<std::uint8_t>((*mhi << 4) | *mlo);
  }

  auto req = co_await http::
      read_request<rwgps::webhook::hmac_body<rwgps::webhook::json_body>>(
          ctx, std::move(r), rwgps_creds_->api_secret());

  if (req.body().mac() != rwgps_sig_decoded)
  {
    throw std::runtime_error{"unhandled: incorrect signature provided"};
  }

  // TODO: handle conversion failure gracefully
  inner_.rwgps_webhook(
      *mrwgps_ts, json::value_to<rwgps::webhook_request>(req.body().get()));

  auto rsp = http::make_rsp<bhttp::empty_body>(
      bhttp::status::ok, http::keep_alive{true});
  rsp.prepare_payload();
  co_return rsp;
}

handler::handler(
    log::logger const& l, api::handler&& inner,
    std::shared_ptr<rwgps::credentials> rwgps_creds)
  : l_{l.sub("handler")}, inner_{std::move(inner)},
    rwgps_creds_{std::move(rwgps_creds)}
{
}

auto handler::make_routes() -> http::route_tree<http::routed_ctx<outer_ctx>>
{
  auto handler = [this]<class MemFn>(MemFn member)
  { return std::bind_front(member, this); };

  return http::dtree<http::routed_ctx<outer_ctx>>{}.named_subtrees({
    {"gpx", http::dtree<l0_ctx>{{
                                  .post = handler(&handler::handle_process_gpx),
                                }}
                .no_subtrees()},
    {"sysinfo", http::dtree<l0_ctx>{{
                                      .get = handler(&handler::handle_sysinfo),
                                    }}
                    .no_subtrees()},
    {"webhook", http::dtree<l0_ctx>{}.named_subtrees({
                  {"rwgps", http::dtree<l0_ctx>{
                              {.post = handler(&handler::handle_rwgps_webhook)}
                            }.no_subtrees()},
                })},
  });
}

auto server::make_global_middleware(config::http_server const& cfg)
    -> http::middleware_t<http::base_ctx, handler::outer_ctx>
{
  return http::
      middleware_compose<http::base_ctx, http::base_ctx, http::base_ctx>(
          http::expose_content_language_middleware<http::base_ctx>,
          middleware_compose<http::base_ctx, http::base_ctx, http::base_ctx>(
              http::expose_trace_id_middleware<http::base_ctx>,
              http::cors_middleware<http::base_ctx>(cfg.allow_origins)));
}

server::server(
    log::logger const& l, config::http_server const& cfg,
    std::shared_ptr<rwgps::credentials> rwgps_creds, locale::selector&& lsel,
    api::handler&& inner)
  : handler_{l, std::move(inner), std::move(rwgps_creds)},
    srv_{
      l,
      http::router{
        l, std::move(lsel), make_global_middleware(cfg), handler_.make_routes()
      }
    }
{
}

auto server::spawn(net::io_context& ioc) -> void { srv_.spawn(ioc); }

} // namespace routemon::srv