this repo has no description
1pub mod api;
2pub mod appview;
3pub mod auth;
4pub mod cache;
5pub mod circuit_breaker;
6pub mod comms;
7pub mod config;
8pub mod crawlers;
9pub mod delegation;
10pub mod handle;
11pub mod image;
12pub mod metrics;
13pub mod oauth;
14pub mod plc;
15pub mod rate_limit;
16pub mod repo;
17pub mod state;
18pub mod storage;
19pub mod sync;
20pub mod util;
21pub mod validation;
22
23use axum::{
24 Router,
25 http::Method,
26 middleware,
27 routing::{any, get, post},
28};
29use state::AppState;
30use tower_http::cors::{Any, CorsLayer};
31use tower_http::services::{ServeDir, ServeFile};
32
33pub fn app(state: AppState) -> Router {
34 let router = Router::new()
35 .route("/metrics", get(metrics::metrics_handler))
36 .route("/health", get(api::server::health))
37 .route("/xrpc/_health", get(api::server::health))
38 .route("/robots.txt", get(api::server::robots_txt))
39 .route("/logo", get(api::server::get_logo))
40 .route(
41 "/xrpc/com.atproto.server.describeServer",
42 get(api::server::describe_server),
43 )
44 .route(
45 "/xrpc/com.atproto.server.createAccount",
46 post(api::identity::create_account),
47 )
48 .route(
49 "/xrpc/com.atproto.server.createSession",
50 post(api::server::create_session),
51 )
52 .route(
53 "/xrpc/com.atproto.server.getSession",
54 get(api::server::get_session),
55 )
56 .route(
57 "/xrpc/com.tranquil.account.listSessions",
58 get(api::server::list_sessions),
59 )
60 .route(
61 "/xrpc/com.tranquil.account.revokeSession",
62 post(api::server::revoke_session),
63 )
64 .route(
65 "/xrpc/com.tranquil.account.revokeAllSessions",
66 post(api::server::revoke_all_sessions),
67 )
68 .route(
69 "/xrpc/com.atproto.server.deleteSession",
70 post(api::server::delete_session),
71 )
72 .route(
73 "/xrpc/com.atproto.server.refreshSession",
74 post(api::server::refresh_session),
75 )
76 .route(
77 "/xrpc/com.atproto.server.confirmSignup",
78 post(api::server::confirm_signup),
79 )
80 .route(
81 "/xrpc/com.atproto.server.resendVerification",
82 post(api::server::resend_verification),
83 )
84 .route(
85 "/xrpc/com.atproto.server.getServiceAuth",
86 get(api::server::get_service_auth),
87 )
88 .route(
89 "/xrpc/com.atproto.identity.resolveHandle",
90 get(api::identity::resolve_handle),
91 )
92 .route(
93 "/xrpc/com.atproto.repo.createRecord",
94 post(api::repo::create_record),
95 )
96 .route(
97 "/xrpc/com.atproto.repo.putRecord",
98 post(api::repo::put_record),
99 )
100 .route(
101 "/xrpc/com.atproto.repo.getRecord",
102 get(api::repo::get_record),
103 )
104 .route(
105 "/xrpc/com.atproto.repo.deleteRecord",
106 post(api::repo::delete_record),
107 )
108 .route(
109 "/xrpc/com.atproto.repo.listRecords",
110 get(api::repo::list_records),
111 )
112 .route(
113 "/xrpc/com.atproto.repo.describeRepo",
114 get(api::repo::describe_repo),
115 )
116 .route(
117 "/xrpc/com.atproto.repo.uploadBlob",
118 post(api::repo::upload_blob),
119 )
120 .route(
121 "/xrpc/com.atproto.repo.applyWrites",
122 post(api::repo::apply_writes),
123 )
124 .route(
125 "/xrpc/com.atproto.sync.getLatestCommit",
126 get(sync::get_latest_commit),
127 )
128 .route("/xrpc/com.atproto.sync.listRepos", get(sync::list_repos))
129 .route("/xrpc/com.atproto.sync.getBlob", get(sync::get_blob))
130 .route("/xrpc/com.atproto.sync.listBlobs", get(sync::list_blobs))
131 .route(
132 "/xrpc/com.atproto.sync.getRepoStatus",
133 get(sync::get_repo_status),
134 )
135 .route(
136 "/xrpc/com.atproto.server.checkAccountStatus",
137 get(api::server::check_account_status),
138 )
139 .route(
140 "/xrpc/com.atproto.identity.getRecommendedDidCredentials",
141 get(api::identity::get_recommended_did_credentials),
142 )
143 .route(
144 "/xrpc/com.atproto.repo.listMissingBlobs",
145 get(api::repo::list_missing_blobs),
146 )
147 .route(
148 "/xrpc/com.atproto.sync.notifyOfUpdate",
149 post(sync::notify_of_update),
150 )
151 .route(
152 "/xrpc/com.atproto.sync.requestCrawl",
153 post(sync::request_crawl),
154 )
155 .route("/xrpc/com.atproto.sync.getBlocks", get(sync::get_blocks))
156 .route("/xrpc/com.atproto.sync.getRepo", get(sync::get_repo))
157 .route("/xrpc/com.atproto.sync.getRecord", get(sync::get_record))
158 .route(
159 "/xrpc/com.atproto.sync.subscribeRepos",
160 get(sync::subscribe_repos),
161 )
162 .route("/xrpc/com.atproto.sync.getHead", get(sync::get_head))
163 .route(
164 "/xrpc/com.atproto.sync.getCheckout",
165 get(sync::get_checkout),
166 )
167 .route(
168 "/xrpc/com.atproto.moderation.createReport",
169 post(api::moderation::create_report),
170 )
171 .route(
172 "/xrpc/com.atproto.admin.getAccountInfo",
173 get(api::admin::get_account_info),
174 )
175 .route(
176 "/xrpc/com.atproto.admin.getAccountInfos",
177 get(api::admin::get_account_infos),
178 )
179 .route(
180 "/xrpc/com.atproto.admin.searchAccounts",
181 get(api::admin::search_accounts),
182 )
183 .route(
184 "/xrpc/com.atproto.server.activateAccount",
185 post(api::server::activate_account),
186 )
187 .route(
188 "/xrpc/com.atproto.server.deactivateAccount",
189 post(api::server::deactivate_account),
190 )
191 .route(
192 "/xrpc/com.atproto.server.requestAccountDelete",
193 post(api::server::request_account_delete),
194 )
195 .route(
196 "/xrpc/com.atproto.server.deleteAccount",
197 post(api::server::delete_account),
198 )
199 .route(
200 "/xrpc/com.atproto.server.requestPasswordReset",
201 post(api::server::request_password_reset),
202 )
203 .route(
204 "/xrpc/com.atproto.server.resetPassword",
205 post(api::server::reset_password),
206 )
207 .route(
208 "/xrpc/com.tranquil.account.changePassword",
209 post(api::server::change_password),
210 )
211 .route(
212 "/xrpc/com.tranquil.account.removePassword",
213 post(api::server::remove_password),
214 )
215 .route(
216 "/xrpc/com.tranquil.account.getPasswordStatus",
217 get(api::server::get_password_status),
218 )
219 .route(
220 "/xrpc/com.tranquil.account.getReauthStatus",
221 get(api::server::get_reauth_status),
222 )
223 .route(
224 "/xrpc/com.tranquil.account.reauthPassword",
225 post(api::server::reauth_password),
226 )
227 .route(
228 "/xrpc/com.tranquil.account.reauthTotp",
229 post(api::server::reauth_totp),
230 )
231 .route(
232 "/xrpc/com.tranquil.account.reauthPasskeyStart",
233 post(api::server::reauth_passkey_start),
234 )
235 .route(
236 "/xrpc/com.tranquil.account.reauthPasskeyFinish",
237 post(api::server::reauth_passkey_finish),
238 )
239 .route(
240 "/xrpc/com.tranquil.account.getLegacyLoginPreference",
241 get(api::server::get_legacy_login_preference),
242 )
243 .route(
244 "/xrpc/com.tranquil.account.updateLegacyLoginPreference",
245 post(api::server::update_legacy_login_preference),
246 )
247 .route(
248 "/xrpc/com.tranquil.account.updateLocale",
249 post(api::server::update_locale),
250 )
251 .route(
252 "/xrpc/com.tranquil.account.listTrustedDevices",
253 get(api::server::list_trusted_devices),
254 )
255 .route(
256 "/xrpc/com.tranquil.account.revokeTrustedDevice",
257 post(api::server::revoke_trusted_device),
258 )
259 .route(
260 "/xrpc/com.tranquil.account.updateTrustedDevice",
261 post(api::server::update_trusted_device),
262 )
263 .route(
264 "/xrpc/com.tranquil.account.createPasskeyAccount",
265 post(api::server::create_passkey_account),
266 )
267 .route(
268 "/xrpc/com.tranquil.account.startPasskeyRegistrationForSetup",
269 post(api::server::start_passkey_registration_for_setup),
270 )
271 .route(
272 "/xrpc/com.tranquil.account.completePasskeySetup",
273 post(api::server::complete_passkey_setup),
274 )
275 .route(
276 "/xrpc/com.tranquil.account.requestPasskeyRecovery",
277 post(api::server::request_passkey_recovery),
278 )
279 .route(
280 "/xrpc/com.tranquil.account.recoverPasskeyAccount",
281 post(api::server::recover_passkey_account),
282 )
283 .route(
284 "/xrpc/com.tranquil.account.getMigrationStatus",
285 get(api::server::get_migration_status),
286 )
287 .route(
288 "/xrpc/com.tranquil.account.updateMigrationForwarding",
289 post(api::server::update_migration_forwarding),
290 )
291 .route(
292 "/xrpc/com.tranquil.account.clearMigrationForwarding",
293 post(api::server::clear_migration_forwarding),
294 )
295 .route(
296 "/xrpc/com.atproto.server.requestEmailUpdate",
297 post(api::server::request_email_update),
298 )
299 .route(
300 "/xrpc/com.atproto.server.confirmEmail",
301 post(api::server::confirm_email),
302 )
303 .route(
304 "/xrpc/com.atproto.server.updateEmail",
305 post(api::server::update_email),
306 )
307 .route(
308 "/xrpc/com.atproto.server.reserveSigningKey",
309 post(api::server::reserve_signing_key),
310 )
311 .route(
312 "/xrpc/com.atproto.server.verifyMigrationEmail",
313 post(api::server::verify_migration_email),
314 )
315 .route(
316 "/xrpc/com.atproto.server.resendMigrationVerification",
317 post(api::server::resend_migration_verification),
318 )
319 .route(
320 "/xrpc/com.atproto.identity.updateHandle",
321 post(api::identity::update_handle),
322 )
323 .route(
324 "/xrpc/com.atproto.identity.requestPlcOperationSignature",
325 post(api::identity::request_plc_operation_signature),
326 )
327 .route(
328 "/xrpc/com.atproto.identity.signPlcOperation",
329 post(api::identity::sign_plc_operation),
330 )
331 .route(
332 "/xrpc/com.atproto.identity.submitPlcOperation",
333 post(api::identity::submit_plc_operation),
334 )
335 .route(
336 "/xrpc/com.atproto.repo.importRepo",
337 post(api::repo::import_repo),
338 )
339 .route(
340 "/xrpc/com.atproto.admin.deleteAccount",
341 post(api::admin::delete_account),
342 )
343 .route(
344 "/xrpc/com.atproto.admin.updateAccountEmail",
345 post(api::admin::update_account_email),
346 )
347 .route(
348 "/xrpc/com.atproto.admin.updateAccountHandle",
349 post(api::admin::update_account_handle),
350 )
351 .route(
352 "/xrpc/com.atproto.admin.updateAccountPassword",
353 post(api::admin::update_account_password),
354 )
355 .route(
356 "/xrpc/com.atproto.server.listAppPasswords",
357 get(api::server::list_app_passwords),
358 )
359 .route(
360 "/xrpc/com.atproto.server.createAppPassword",
361 post(api::server::create_app_password),
362 )
363 .route(
364 "/xrpc/com.atproto.server.revokeAppPassword",
365 post(api::server::revoke_app_password),
366 )
367 .route(
368 "/xrpc/com.atproto.server.createInviteCode",
369 post(api::server::create_invite_code),
370 )
371 .route(
372 "/xrpc/com.atproto.server.createInviteCodes",
373 post(api::server::create_invite_codes),
374 )
375 .route(
376 "/xrpc/com.atproto.server.getAccountInviteCodes",
377 get(api::server::get_account_invite_codes),
378 )
379 .route(
380 "/xrpc/com.atproto.server.createTotpSecret",
381 post(api::server::create_totp_secret),
382 )
383 .route(
384 "/xrpc/com.atproto.server.enableTotp",
385 post(api::server::enable_totp),
386 )
387 .route(
388 "/xrpc/com.atproto.server.disableTotp",
389 post(api::server::disable_totp),
390 )
391 .route(
392 "/xrpc/com.atproto.server.getTotpStatus",
393 get(api::server::get_totp_status),
394 )
395 .route(
396 "/xrpc/com.atproto.server.regenerateBackupCodes",
397 post(api::server::regenerate_backup_codes),
398 )
399 .route(
400 "/xrpc/com.atproto.server.startPasskeyRegistration",
401 post(api::server::start_passkey_registration),
402 )
403 .route(
404 "/xrpc/com.atproto.server.finishPasskeyRegistration",
405 post(api::server::finish_passkey_registration),
406 )
407 .route(
408 "/xrpc/com.atproto.server.listPasskeys",
409 get(api::server::list_passkeys),
410 )
411 .route(
412 "/xrpc/com.atproto.server.deletePasskey",
413 post(api::server::delete_passkey),
414 )
415 .route(
416 "/xrpc/com.atproto.server.updatePasskey",
417 post(api::server::update_passkey),
418 )
419 .route(
420 "/xrpc/com.atproto.admin.getInviteCodes",
421 get(api::admin::get_invite_codes),
422 )
423 .route(
424 "/xrpc/com.tranquil.admin.getServerStats",
425 get(api::admin::get_server_stats),
426 )
427 .route(
428 "/xrpc/com.tranquil.server.getConfig",
429 get(api::admin::get_server_config),
430 )
431 .route(
432 "/xrpc/com.tranquil.admin.updateServerConfig",
433 post(api::admin::update_server_config),
434 )
435 .route(
436 "/xrpc/com.atproto.admin.disableAccountInvites",
437 post(api::admin::disable_account_invites),
438 )
439 .route(
440 "/xrpc/com.atproto.admin.enableAccountInvites",
441 post(api::admin::enable_account_invites),
442 )
443 .route(
444 "/xrpc/com.atproto.admin.disableInviteCodes",
445 post(api::admin::disable_invite_codes),
446 )
447 .route(
448 "/xrpc/com.atproto.admin.getSubjectStatus",
449 get(api::admin::get_subject_status),
450 )
451 .route(
452 "/xrpc/com.atproto.admin.updateSubjectStatus",
453 post(api::admin::update_subject_status),
454 )
455 .route(
456 "/xrpc/com.atproto.admin.sendEmail",
457 post(api::admin::send_email),
458 )
459 .route(
460 "/xrpc/app.bsky.actor.getPreferences",
461 get(api::actor::get_preferences),
462 )
463 .route(
464 "/xrpc/app.bsky.actor.putPreferences",
465 post(api::actor::put_preferences),
466 )
467 .route("/.well-known/did.json", get(api::identity::well_known_did))
468 .route(
469 "/.well-known/atproto-did",
470 get(api::identity::well_known_atproto_did),
471 )
472 .route("/u/{handle}/did.json", get(api::identity::user_did_doc))
473 .route(
474 "/.well-known/oauth-protected-resource",
475 get(oauth::endpoints::oauth_protected_resource),
476 )
477 .route(
478 "/.well-known/oauth-authorization-server",
479 get(oauth::endpoints::oauth_authorization_server),
480 )
481 .route("/oauth/jwks", get(oauth::endpoints::oauth_jwks))
482 .route(
483 "/oauth/client-metadata.json",
484 get(oauth::endpoints::frontend_client_metadata),
485 )
486 .route(
487 "/oauth/par",
488 post(oauth::endpoints::pushed_authorization_request),
489 )
490 .route("/oauth/authorize", get(oauth::endpoints::authorize_get))
491 .route("/oauth/authorize", post(oauth::endpoints::authorize_post))
492 .route(
493 "/oauth/authorize/accounts",
494 get(oauth::endpoints::authorize_accounts),
495 )
496 .route(
497 "/oauth/authorize/select",
498 post(oauth::endpoints::authorize_select),
499 )
500 .route(
501 "/oauth/authorize/2fa",
502 get(oauth::endpoints::authorize_2fa_get),
503 )
504 .route(
505 "/oauth/authorize/2fa",
506 post(oauth::endpoints::authorize_2fa_post),
507 )
508 .route(
509 "/oauth/authorize/passkey",
510 get(oauth::endpoints::authorize_passkey_start),
511 )
512 .route(
513 "/oauth/authorize/passkey",
514 post(oauth::endpoints::authorize_passkey_finish),
515 )
516 .route(
517 "/oauth/passkey/check",
518 get(oauth::endpoints::check_user_has_passkeys),
519 )
520 .route(
521 "/oauth/security-status",
522 get(oauth::endpoints::check_user_security_status),
523 )
524 .route(
525 "/oauth/passkey/start",
526 post(oauth::endpoints::passkey_start),
527 )
528 .route(
529 "/oauth/passkey/finish",
530 post(oauth::endpoints::passkey_finish),
531 )
532 .route(
533 "/oauth/authorize/deny",
534 post(oauth::endpoints::authorize_deny),
535 )
536 .route(
537 "/oauth/authorize/consent",
538 get(oauth::endpoints::consent_get),
539 )
540 .route(
541 "/oauth/authorize/consent",
542 post(oauth::endpoints::consent_post),
543 )
544 .route(
545 "/oauth/delegation/auth",
546 post(oauth::endpoints::delegation_auth),
547 )
548 .route(
549 "/oauth/delegation/totp",
550 post(oauth::endpoints::delegation_totp_verify),
551 )
552 .route("/oauth/token", post(oauth::endpoints::token_endpoint))
553 .route("/oauth/revoke", post(oauth::endpoints::revoke_token))
554 .route(
555 "/oauth/introspect",
556 post(oauth::endpoints::introspect_token),
557 )
558 .route(
559 "/xrpc/com.atproto.temp.checkSignupQueue",
560 get(api::temp::check_signup_queue),
561 )
562 .route(
563 "/xrpc/com.atproto.temp.dereferenceScope",
564 post(api::temp::dereference_scope),
565 )
566 .route(
567 "/xrpc/com.tranquil.account.getNotificationPrefs",
568 get(api::notification_prefs::get_notification_prefs),
569 )
570 .route(
571 "/xrpc/com.tranquil.account.updateNotificationPrefs",
572 post(api::notification_prefs::update_notification_prefs),
573 )
574 .route(
575 "/xrpc/com.tranquil.account.getNotificationHistory",
576 get(api::notification_prefs::get_notification_history),
577 )
578 .route(
579 "/xrpc/com.tranquil.account.confirmChannelVerification",
580 post(api::verification::confirm_channel_verification),
581 )
582 .route(
583 "/xrpc/com.tranquil.account.verifyToken",
584 post(api::server::verify_token),
585 )
586 .route(
587 "/xrpc/com.tranquil.delegation.listControllers",
588 get(api::delegation::list_controllers),
589 )
590 .route(
591 "/xrpc/com.tranquil.delegation.addController",
592 post(api::delegation::add_controller),
593 )
594 .route(
595 "/xrpc/com.tranquil.delegation.removeController",
596 post(api::delegation::remove_controller),
597 )
598 .route(
599 "/xrpc/com.tranquil.delegation.updateControllerScopes",
600 post(api::delegation::update_controller_scopes),
601 )
602 .route(
603 "/xrpc/com.tranquil.delegation.listControlledAccounts",
604 get(api::delegation::list_controlled_accounts),
605 )
606 .route(
607 "/xrpc/com.tranquil.delegation.getAuditLog",
608 get(api::delegation::get_audit_log),
609 )
610 .route(
611 "/xrpc/com.tranquil.delegation.getScopePresets",
612 get(api::delegation::get_scope_presets),
613 )
614 .route(
615 "/xrpc/com.tranquil.delegation.createDelegatedAccount",
616 post(api::delegation::create_delegated_account),
617 )
618 .route("/xrpc/{*method}", any(api::proxy::proxy_handler))
619 .layer(middleware::from_fn(metrics::metrics_middleware))
620 .layer(
621 CorsLayer::new()
622 .allow_origin(Any)
623 .allow_methods([Method::GET, Method::POST, Method::OPTIONS])
624 .allow_headers(Any),
625 )
626 .with_state(state);
627
628 let frontend_dir =
629 std::env::var("FRONTEND_DIR").unwrap_or_else(|_| "./frontend/dist".to_string());
630
631 if std::path::Path::new(&frontend_dir)
632 .join("index.html")
633 .exists()
634 {
635 let index_path = format!("{}/index.html", frontend_dir);
636 let serve_dir = ServeDir::new(&frontend_dir).not_found_service(ServeFile::new(index_path));
637 router.fallback_service(serve_dir)
638 } else {
639 router
640 }
641}