Skip to main content

Config

Struct Config 

Source
pub struct Config {
    pub root: PathBuf,
    pub trailing_slash: bool,
    pub seo_inject: Option<SeoInject>,
    pub api_prefixes: Option<Vec<String>>,
    pub spa_fallback: bool,
    pub not_found: Option<NotFoundHandler>,
    pub disable_cache: bool,
    pub html_cache_max_bytes: i64,
}
Available on crate feature nextstatic only.
Expand description

托管配置; 用 Config::new 指定导出目录, 其余按需覆盖

Fields§

§root: PathBuf

Next.js export 产物目录 (out/), 必填

§trailing_slash: bool

与 next.config 的 trailingSlash: true 对齐; 开启后无扩展名页面请求先 308 补斜杠

§seo_inject: Option<SeoInject>

可选的 HTML 注入钩子, 写出任何 HTML 前调用 (含动态路由占位模板与 404 页)

§api_prefixes: Option<Vec<String>>

命中这些前缀的请求返回 JSON 404, 不落页面兜底; None 默认 ["/api/"], Some(vec![]) 关闭

§spa_fallback: bool

页面未命中时兜底根 index.html 并返回 200 (纯 SPA 形态); 默认返回 404.html + 404

§not_found: Option<NotFoundHandler>

自定义 404 处理器, 替代默认的 404.html 逻辑

§disable_cache: bool

关闭文件索引与 HTML 缓存, 每次请求读盘; 只用于本地开发

§html_cache_max_bytes: i64

HTML 内存缓存总量上限; 零默认 64MB, 负值关闭 HTML 缓存 (文件索引仍生效); 达到上限后新页面每次读盘

Implementations§

Source§

impl Config

Source

pub fn new(root: impl Into<PathBuf>) -> Self

以导出目录创建默认配置

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Config

§

impl !UnwindSafe for Config

§

impl Forget for Config

§

impl Freeze for Config
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const ArcInner<dyn Fn(&Parts, Bytes) -> Bytes + Sync + Send> is !null: Freeze, PhantomData<ArcInner<dyn Fn(&Parts, Bytes) -> Bytes + Sync + Send>>: Freeze, PhantomData<String>: Freeze, *const ArcInner<dyn Fn(&Parts) -> Response<Bytes> + Sync + Send> is !null: Freeze, PhantomData<ArcInner<dyn Fn(&Parts) -> Response<Bytes> + Sync + Send>>: Freeze,

§

impl Move for Config

§

impl Send for Config
where RawVecInner: Send, Arc<dyn Fn(&Parts, Bytes) -> Bytes + Sync + Send>: Send, Arc<dyn Fn(&Parts) -> Response<Bytes> + Sync + Send>: Send,

§

impl Sync for Config
where RawVecInner: Sync, Arc<dyn Fn(&Parts, Bytes) -> Bytes + Sync + Send>: Sync, Arc<dyn Fn(&Parts) -> Response<Bytes> + Sync + Send>: Sync,

§

impl Unpin for Config
where *const u8 is !null: Unpin, Arc<dyn Fn(&Parts, Bytes) -> Bytes + Sync + Send>: Unpin, Arc<dyn Fn(&Parts) -> Response<Bytes> + Sync + Send>: Unpin,

§

impl UnsafeUnpin for Config
where *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const ArcInner<dyn Fn(&Parts, Bytes) -> Bytes + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(&Parts, Bytes) -> Bytes + Sync + Send>>: UnsafeUnpin, PhantomData<String>: UnsafeUnpin, *const ArcInner<dyn Fn(&Parts) -> Response<Bytes> + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(&Parts) -> Response<Bytes> + Sync + Send>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.