You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-07-29 22:01:14 +03:00
Do not embed the templates and static files in the binary
This commit is contained in:
@ -49,7 +49,6 @@ mas-listener = { path = "../listener" }
|
||||
mas-policy = { path = "../policy" }
|
||||
mas-router = { path = "../router" }
|
||||
mas-spa = { path = "../spa" }
|
||||
mas-static-files = { path = "../static-files" }
|
||||
mas-storage = { path = "../storage" }
|
||||
mas-tasks = { path = "../tasks" }
|
||||
mas-templates = { path = "../templates" }
|
||||
@ -71,9 +70,6 @@ native-roots = ["mas-http/native-roots", "mas-handlers/native-roots"]
|
||||
# Use the webpki root certificates
|
||||
webpki-roots = ["mas-http/webpki-roots", "mas-handlers/webpki-roots"]
|
||||
|
||||
# Read the builtin static files and templates from the source directory
|
||||
dev = ["mas-templates/dev", "mas-static-files/dev"]
|
||||
|
||||
# Enable OpenTelemetry OTLP exporter.
|
||||
otlp = ["dep:opentelemetry-otlp"]
|
||||
# Enable OpenTelemetry Jaeger exporter and propagator.
|
||||
|
@ -55,44 +55,36 @@ async fn watch_templates(
|
||||
|
||||
let templates = templates.clone();
|
||||
|
||||
// Find which roots we're supposed to watch
|
||||
let roots = templates.watch_roots().await;
|
||||
let mut streams = Vec::new();
|
||||
// Find which root we're supposed to watch
|
||||
let root = templates.watch_root();
|
||||
|
||||
for root in roots {
|
||||
// For each root, create a subscription
|
||||
let resolved = client
|
||||
.resolve_root(CanonicalPath::canonicalize(root)?)
|
||||
.await?;
|
||||
// For each root, create a subscription
|
||||
let resolved = client
|
||||
.resolve_root(CanonicalPath::canonicalize(root)?)
|
||||
.await?;
|
||||
|
||||
// TODO: we could subscribe to less, properly filter here
|
||||
let (subscription, _) = client
|
||||
.subscribe::<NameOnly>(&resolved, SubscribeRequest::default())
|
||||
.await?;
|
||||
// TODO: we could subscribe to less, properly filter here
|
||||
let (subscription, _) = client
|
||||
.subscribe::<NameOnly>(&resolved, SubscribeRequest::default())
|
||||
.await?;
|
||||
|
||||
// Create a stream out of that subscription
|
||||
let stream = futures_util::stream::try_unfold(subscription, |mut sub| async move {
|
||||
let next = sub.next().await?;
|
||||
anyhow::Ok(Some((next, sub)))
|
||||
});
|
||||
|
||||
streams.push(Box::pin(stream));
|
||||
}
|
||||
|
||||
let files_changed_stream =
|
||||
futures_util::stream::select_all(streams).try_filter_map(|event| async move {
|
||||
match event {
|
||||
SubscriptionData::FilesChanged(QueryResult {
|
||||
files: Some(files), ..
|
||||
}) => {
|
||||
let files: Vec<_> = files.into_iter().map(|f| f.name.into_inner()).collect();
|
||||
Ok(Some(files))
|
||||
}
|
||||
_ => Ok(None),
|
||||
// Create a stream out of that subscription
|
||||
let fut = futures_util::stream::try_unfold(subscription, |mut sub| async move {
|
||||
let next = sub.next().await?;
|
||||
anyhow::Ok(Some((next, sub)))
|
||||
})
|
||||
.try_filter_map(|event| async move {
|
||||
match event {
|
||||
SubscriptionData::FilesChanged(QueryResult {
|
||||
files: Some(files), ..
|
||||
}) => {
|
||||
let files: Vec<_> = files.into_iter().map(|f| f.name.into_inner()).collect();
|
||||
Ok(Some(files))
|
||||
}
|
||||
});
|
||||
|
||||
let fut = files_changed_stream.for_each(move |files| {
|
||||
_ => Ok(None),
|
||||
}
|
||||
})
|
||||
.for_each(move |files| {
|
||||
let templates = templates.clone();
|
||||
async move {
|
||||
info!(?files, "Files changed, reloading templates");
|
||||
@ -162,13 +154,9 @@ impl Options {
|
||||
let url_builder = UrlBuilder::new(config.http.public_base.clone());
|
||||
|
||||
// Load and compile the templates
|
||||
let templates = Templates::load(
|
||||
config.templates.path.clone(),
|
||||
config.templates.builtin,
|
||||
url_builder.clone(),
|
||||
)
|
||||
.await
|
||||
.context("could not load templates")?;
|
||||
let templates = Templates::load(config.templates.path.clone(), url_builder.clone())
|
||||
.await
|
||||
.context("could not load templates")?;
|
||||
|
||||
let mailer = Mailer::new(
|
||||
&templates,
|
||||
|
@ -25,24 +25,10 @@ pub(super) struct Options {
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
enum Subcommand {
|
||||
/// Save the builtin templates to a folder
|
||||
Save {
|
||||
/// Where the templates should be saved
|
||||
path: Utf8PathBuf,
|
||||
|
||||
/// Overwrite existing template files
|
||||
#[arg(long)]
|
||||
overwrite: bool,
|
||||
},
|
||||
|
||||
/// Check for template validity at given path.
|
||||
Check {
|
||||
/// Path where the templates are
|
||||
path: String,
|
||||
|
||||
/// Skip loading builtin templates
|
||||
#[arg(long)]
|
||||
skip_builtin: bool,
|
||||
path: Utf8PathBuf,
|
||||
},
|
||||
}
|
||||
|
||||
@ -50,17 +36,10 @@ impl Options {
|
||||
pub async fn run(&self, _root: &super::Options) -> anyhow::Result<()> {
|
||||
use Subcommand as SC;
|
||||
match &self.subcommand {
|
||||
SC::Save { path, overwrite } => {
|
||||
Templates::save(path, *overwrite).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
SC::Check { path, skip_builtin } => {
|
||||
SC::Check { path } => {
|
||||
let clock = Clock::default();
|
||||
let url_builder = mas_router::UrlBuilder::new("https://example.com/".parse()?);
|
||||
let templates =
|
||||
Templates::load(Some(path.into()), !skip_builtin, url_builder).await?;
|
||||
let templates = Templates::load(path.clone(), url_builder).await?;
|
||||
templates.check_render(clock.now()).await?;
|
||||
|
||||
Ok(())
|
||||
|
@ -59,9 +59,15 @@ where
|
||||
mas_config::HttpResource::GraphQL { playground } => {
|
||||
router.merge(mas_handlers::graphql_router::<AppState, B>(*playground))
|
||||
}
|
||||
mas_config::HttpResource::Static { web_root } => {
|
||||
let handler = mas_static_files::service(web_root.as_deref());
|
||||
router.nest_service(mas_router::StaticAsset::route(), handler)
|
||||
mas_config::HttpResource::Assets { path } => {
|
||||
let static_service = ServeDir::new(path).append_index_html_on_directories(false);
|
||||
let error_layer =
|
||||
HandleErrorLayer::new(|_e| ready(StatusCode::INTERNAL_SERVER_ERROR));
|
||||
|
||||
router.nest_service(
|
||||
mas_router::StaticAsset::route(),
|
||||
error_layer.layer(static_service),
|
||||
)
|
||||
}
|
||||
mas_config::HttpResource::OAuth => {
|
||||
router.merge(mas_handlers::api_router::<AppState, B>())
|
||||
@ -77,13 +83,11 @@ where
|
||||
}),
|
||||
),
|
||||
|
||||
mas_config::HttpResource::Spa { assets, manifest } => {
|
||||
mas_config::HttpResource::Spa { manifest } => {
|
||||
let error_layer =
|
||||
HandleErrorLayer::new(|_e| ready(StatusCode::INTERNAL_SERVER_ERROR));
|
||||
|
||||
// TODO: split the assets service and the index service, and make those paths
|
||||
// configurable
|
||||
let assets_base = "/app-assets/";
|
||||
// TODO: make those paths configurable
|
||||
let app_base = "/app/";
|
||||
|
||||
// TODO: make that config typed and configurable
|
||||
@ -91,14 +95,13 @@ where
|
||||
"root": app_base,
|
||||
});
|
||||
|
||||
let index_service =
|
||||
ViteManifestService::new(manifest.clone(), assets_base.into(), config);
|
||||
let index_service = ViteManifestService::new(
|
||||
manifest.clone(),
|
||||
mas_router::StaticAsset::route().into(),
|
||||
config,
|
||||
);
|
||||
|
||||
let static_service = ServeDir::new(assets).append_index_html_on_directories(false);
|
||||
|
||||
router
|
||||
.nest_service(app_base, error_layer.layer(index_service))
|
||||
.nest_service(assets_base, error_layer.layer(static_service))
|
||||
router.nest_service(app_base, error_layer.layer(index_service))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user