Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nestjs/serve-static
Serve static websites (SPA's) using Nest framework (node.js) 🥦
https://github.com/nestjs/serve-static
javascript nestjs node node-framework nodejs serve-static typescript
Last synced: about 1 month ago
JSON representation
Serve static websites (SPA's) using Nest framework (node.js) 🥦
- Host: GitHub
- URL: https://github.com/nestjs/serve-static
- Owner: nestjs
- License: mit
- Created: 2019-07-17T19:22:27.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-04-12T10:53:40.000Z (7 months ago)
- Last Synced: 2024-04-14T09:34:46.908Z (7 months ago)
- Topics: javascript, nestjs, node, node-framework, nodejs, serve-static, typescript
- Language: TypeScript
- Homepage: https://nestjs.com/
- Size: 3.34 MB
- Stars: 432
- Watchers: 5
- Forks: 45
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
[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.
## Description
`@nestjs/serve-static` package for [Nest](https://github.com/nestjs/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](https://docs.nestjs.com/techniques/mvc)) instead.
## Installation
```bash
$ npm i --save @nestjs/serve-static
```## Example
See full example [here](https://github.com/nestjs/nest/tree/master/sample/24-serve-static).
## Usage
Simply import `ServeStaticModule` in your Nest application.
```typescript
import { Module } from '@nestjs/common';
import { join } from 'path';
import { ServeStaticModule } from '@nestjs/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](https://docs.nestjs.com/support).
## Stay in touch
- Author - [Kamil Myśliwiec](https://twitter.com/kammysliwiec)
- Website - [https://nestjs.com](https://nestjs.com/)
- Twitter - [@nestframework](https://twitter.com/nestframework)## License
Nest is [MIT licensed](LICENSE).