-
Notifications
You must be signed in to change notification settings - Fork 640
/
Copy pathlib.rs
81 lines (73 loc) · 1.98 KB
/
lib.rs
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
//! This crate implements the backend server for <https://crates.io/>
//!
//! All implemented routes are defined in the [middleware](fn.middleware.html) function and
//! implemented in the [category](category/index.html), [keyword](keyword/index.html),
//! [krate](krate/index.html), [user](user/index.html) and [version](version/index.html) modules.
#[cfg(test)]
#[macro_use]
extern crate claims;
#[macro_use]
extern crate diesel;
#[macro_use]
extern crate serde;
#[macro_use]
extern crate tracing;
pub use crate::{app::App, email::Emails};
pub use crates_io_database::{models, schema};
use std::sync::Arc;
use crate::app::AppState;
use crate::router::build_axum_router;
use tikv_jemallocator::Jemalloc;
#[global_allocator]
static ALLOC: Jemalloc = Jemalloc;
mod app;
pub mod auth;
pub mod boot;
pub mod certs;
pub mod cloudfront;
pub mod config;
pub mod controllers;
pub mod db;
pub mod email;
pub mod external_urls;
pub mod fastly;
pub mod headers;
pub mod index;
mod licenses;
pub mod metrics;
pub mod middleware;
pub mod openapi;
pub mod rate_limiter;
mod real_ip;
mod router;
pub mod sentry;
pub mod sqs;
pub mod ssh;
pub mod storage;
pub mod tasks;
#[cfg(test)]
pub mod tests;
pub mod typosquat;
pub mod util;
pub mod views;
pub mod worker;
/// Used for setting different values depending on whether the app is being run in production,
/// in development, or for testing.
///
/// The app's `config.env` value is set in *src/bin/server.rs* to `Production` if the environment
/// variable `HEROKU` is set and `Development` otherwise. `config.env` is set to `Test`
/// unconditionally in *src/test/all.rs*.
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
pub enum Env {
Development,
Test,
Production,
}
/// Configures routes, sessions, logging, and other middleware.
///
/// Called from *src/bin/server.rs*.
pub fn build_handler(app: Arc<App>) -> axum::Router {
let state = AppState(app);
let axum_router = build_axum_router(state.clone());
middleware::apply_axum_middleware(state, axum_router)
}