@7rulnik/nest-serve-static 中文文档教程

发布于 3年前 浏览 21 项目主页 更新于 3年前

Nest Logo

[特拉维斯形象]:https://api.travis-ci.org/nestjs/nest.svg?branch=master [特拉维斯网址]:https://travis-ci.org/nestjs/nest [linux-image]: https://img.shields.io/travis/nestjs/nest/master.svg?label=linux [linux-url]: https://travis-ci.org/nestjs/nest

一个渐进的 Node.js 构建框架高效且可扩展的服务器端应用程序。

<p align="center">

NPM 版本 包许可证 NPM 下载 特拉维斯”></a> 
  <a href=Linux 覆盖范围 Discord Open Collective 的支持者 Open Collective 赞助商

Description

@7rulnik/nest-serve-static 用于 Nest 的包,可用于提供静态内容,如单页应用程序(温泉)。 但是,如果您正在构建 MVC 应用程序或想要提供资产文件(图像、文档),请使用 useStaticAssets() 方法(阅读更多 此处) 代替。

Installation

$ npm i --save @7rulnik/nest-serve-static

Example

请在此处查看完整示例。

Usage

只需在您的 Nest 应用程序中导入 ServeStaticModule

import { Module } from '@nestjs/common';
import { join } from 'path';
import { ServeStaticModule } from '@7rulnik/nest-serve-static';

@Module({
  imports: [
    ServeStaticModule.forRoot({
      rootPath: join(__dirname, '..', 'client')
    })
  ]
})
export class ApplicationModule {}

API Spec

forRoot() 方法采用具有一些有用属性的选项对象。

Property Type Description
rootPath string Static files root directory. Default: "client"
serveRoot string Root path under which static app will be served. Default: ""
renderPath string / RegExp Path to render static app (concatenated with the serveRoot value). Default: * (wildcard - all paths). Note: RegExp is not supported by the @nestjs/platform-fastify.
exclude string[] Paths to exclude when serving the static app. WARNING! Not supported by fastify. If you use fastify, you can exclude routes using regexp (set the renderPath to a regular expression) instead.
serveStaticOptions Object Serve static options (static files)

Support

Nest 是 MIT 许可的开源项目。 由于赞助商和惊人支持者的支持,它可以成长。 如果您想加入他们,请在此处阅读更多信息

Stay in touch

License

Nest 已获得 MIT 许可

Nest Logo

[travis-image]: https://api.travis-ci.org/nestjs/nest.svg?branch=master [travis-url]: https://travis-ci.org/nestjs/nest [linux-image]: https://img.shields.io/travis/nestjs/nest/master.svg?label=linux [linux-url]: https://travis-ci.org/nestjs/nest

A progressive Node.js framework for building efficient and scalable server-side applications.

<p align="center">

NPM Version Package License NPM Downloads Travis Linux Coverage Discord Backers on Open Collective Sponsors on Open Collective

Description

@7rulnik/nest-serve-static package for Nest, useful to serve static content like Single Page Applications (SPA). However, if you are building MVC application or want to serve assets files (images, docs), use the useStaticAssets() method (read more here) instead.

Installation

$ npm i --save @7rulnik/nest-serve-static

Example

See full example here.

Usage

Simply import ServeStaticModule in your Nest application.

import { Module } from '@nestjs/common';
import { join } from 'path';
import { ServeStaticModule } from '@7rulnik/nest-serve-static';

@Module({
  imports: [
    ServeStaticModule.forRoot({
      rootPath: join(__dirname, '..', 'client')
    })
  ]
})
export class ApplicationModule {}

API Spec

The forRoot() method takes an options object with a few useful properties.

Property Type Description
rootPath string Static files root directory. Default: "client"
serveRoot string Root path under which static app will be served. Default: ""
renderPath string / RegExp Path to render static app (concatenated with the serveRoot value). Default: * (wildcard - all paths). Note: RegExp is not supported by the @nestjs/platform-fastify.
exclude string[] Paths to exclude when serving the static app. WARNING! Not supported by fastify. If you use fastify, you can exclude routes using regexp (set the renderPath to a regular expression) instead.
serveStaticOptions Object Serve static options (static files)

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

Stay in touch

License

Nest is MIT licensed.

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文