Files
moloapp/example/app/App.hpp
T

97 lines
4.2 KiB
C++
Raw Normal View History

#pragma once
// Demo application assembly: shared Services (the DI skeleton), the root
// Application with middleware, routers, and mounted sub-applications.
// Gap: real molo::di::Container and plugin registry in 05-request-routing.md.
#include <map>
#include <optional>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "../fw/App.hpp"
#include "../fw/Data.hpp"
#include "../fw/Jobs.hpp"
#include "../fw/Kv.hpp"
#include "../fw/Net.hpp"
#include "../fw/Observ.hpp"
#include "../fw/Stats.hpp"
#include "../fw/Templates.hpp"
#include "google/client.h"
#include "google/voice.h"
#include "google/voice_backend.h"
namespace molo::example::app {
struct Services {
std::shared_ptr<fw::KvStore> kv = std::make_shared<fw::KvStore>();
std::shared_ptr<fw::Cache> cache = std::make_shared<fw::Cache>();
std::shared_ptr<fw::Pubsub> pubsub = std::make_shared<fw::Pubsub>();
std::shared_ptr<fw::EventBus> events = std::make_shared<fw::EventBus>();
std::shared_ptr<fw::Stats> stats = std::make_shared<fw::Stats>();
std::shared_ptr<fw::Metrics> metrics = std::make_shared<fw::Metrics>();
std::shared_ptr<fw::Telemetry> telemetry =
std::make_shared<fw::Telemetry>();
std::shared_ptr<fw::SessionStore> sessions =
std::make_shared<fw::SessionStore>();
std::shared_ptr<fw::Auth> auth = std::make_shared<fw::Auth>();
std::shared_ptr<fw::OrmDb> sqlite =
std::make_shared<fw::OrmDb>(fw::OrmBackend::Sqlite);
std::shared_ptr<fw::OrmDb> postgres =
std::make_shared<fw::OrmDb>(fw::OrmBackend::Postgres);
std::shared_ptr<fw::UploadStore> uploads =
std::make_shared<fw::UploadStore>();
std::shared_ptr<fw::WebdavStore> webdav =
std::make_shared<fw::WebdavStore>();
std::shared_ptr<fw::Supervisor> supervisor =
std::make_shared<fw::Supervisor>();
std::shared_ptr<fw::TaskQueue> tasks = std::make_shared<fw::TaskQueue>();
std::shared_ptr<fw::ReplicationLog> repl =
std::make_shared<fw::ReplicationLog>();
std::shared_ptr<fw::OpenApi> openapi = std::make_shared<fw::OpenApi>();
std::shared_ptr<fw::Environment> templates =
std::make_shared<fw::Environment>();
// Google Cloud client (null: built from GOOGLE_API_KEY on first use) and
// the voice pipeline wired on it. Tests inject a scripted client.
std::shared_ptr<google::GoogleClient> google;
std::shared_ptr<google::VoicePipeline> voice;
// Unset: chosen from GOOGLE_API_BACKEND / the key prefix (see src/google).
std::optional<google::VoiceBackend> voice_backend;
// Feature matrix rows (feature, route) shown on the index page. Each
// register_*_demo adds its own rows with add_feature().
std::vector<std::pair<std::string, std::string>> features;
void add_feature(std::string feature, std::string route) {
features.emplace_back(std::move(feature), std::move(route));
}
std::map<std::string, std::string> embedded;
std::string static_root = "example/static";
std::string cookie_secret = "living-example-secret";
};
std::shared_ptr<fw::Application> build_application(Services& services);
void register_index(fw::Router& router, Services& services);
void register_routing_demo(fw::Router& router, Services& services);
void register_chain_demo(std::shared_ptr<fw::Application> app,
Services& services);
void register_data_demo(fw::Router& router, Services& services);
void register_security_demo(fw::Router& router, Services& services);
void register_formats_demo(fw::Router& router, Services& services);
void register_realtime_demo(fw::Router& router, Services& services);
void register_ops_demo(fw::Router& router, Services& services);
void register_doos_demo(fw::Router& router, Services& services);
void register_stats_demo(fw::Router& router, Services& services);
void register_security_extra_demo(fw::Router& router, Services& services);
void register_platform_demo(fw::Router& router, Services& services);
void register_enterprise_demo(fw::Router& router, Services& services);
void register_resilience_demo(fw::Router& router, Services& services);
void register_voice_demo(fw::Router& router, Services& services);
void load_templates(Services& services);
void load_embedded(Services& services);
void seed_services(Services& services);
} // namespace molo::example::app