fastify-file-interceptor
Advanced tools
Comparing version 1.0.8 to 1.0.9
{ | ||
"name": "fastify-file-interceptor", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"main": "dist/index.js", | ||
@@ -17,10 +17,9 @@ "types": "dist/index.d.ts", | ||
"devDependencies": { | ||
"@nestjs/common": "^7.6.15", | ||
"@nestjs/core": "^8.0.2", | ||
"@types/multer": "^1.4.5", | ||
"@nestjs/common": "^10.2.7", | ||
"@types/multer": "^1.4.8", | ||
"@types/node": "^15.0.1", | ||
"@types/uuid": "^8.3.0", | ||
"fastify": "^3.15.1", | ||
"fastify": "^3.24.1", | ||
"reflect-metadata": "^0.1.13", | ||
"rimraf": "^3.0.2", | ||
"rimraf": "^5.0.5", | ||
"rxjs": "^7.0.0", | ||
@@ -27,0 +26,0 @@ "sinon": "^11.1.1", |
@@ -7,6 +7,7 @@ #### Installation | ||
#### Warning | ||
FileFastifyInterceptor() may not be compatible with third party cloud providers like Google Firebase or others,This package is base on fastify-multer | ||
### yarn | ||
### yarn | ||
```shell | ||
@@ -16,16 +17,26 @@ $ yarn add fastify-file-interceptor | ||
--- | ||
```typescript | ||
/* main.ts */ | ||
import { contentParser } from 'fastify-file-interceptor'; | ||
import 'reflect-metadata'; | ||
import { FastifyAdapter,NestFastifyApplication } from '@nestjs/platform-fastify'; | ||
import { join } from "path" | ||
import { NestFactory } from "@nestjs/core"; | ||
import { | ||
FastifyAdapter, | ||
NestFastifyApplication, | ||
} from "@nestjs/platform-fastify"; | ||
import { AppModule } from "./app.module"; | ||
import { contentParser } from "fastify-file-interceptor"; | ||
import "reflect-metadata"; | ||
import { join } from "path"; | ||
import helmet from "@fastify/helmet"; | ||
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger"; | ||
async function bootstrap(): Promise<void> { | ||
const swaggerDocument = new DocumentBuilder() | ||
.setTitle("API") | ||
.setDescription("API") | ||
.setVersion("1.0") | ||
.addTag("API") | ||
.build(); | ||
async function bootstrap() { | ||
const app = await NestFactory.create<NestFastifyApplication>( | ||
@@ -35,9 +46,27 @@ AppModule, | ||
); | ||
await app.listen(3000); | ||
// Note: add this line | ||
await app.register(helmet, { | ||
contentSecurityPolicy: { | ||
directives: { | ||
defaultSrc: [`'self'`], | ||
styleSrc: [`'self'`, `'unsafe-inline'`], | ||
imgSrc: [`'self'`, "data:", "validator.swagger.io"], | ||
scriptSrc: [`'self'`, `https: 'unsafe-inline'`], | ||
}, | ||
}, | ||
}); | ||
// yarn add fastify-multer | ||
// yarn add fastify-static | ||
app.register(contentParser); | ||
app.useStaticAsset({root: join(__dirname,"../../example")}) | ||
await app.register(contentParser); | ||
// yarn add @fastify/static | ||
await app.useStaticAssets({ | ||
root: join(__dirname, "../../example"), | ||
}); | ||
// open API | ||
SwaggerModule.setup( | ||
"api", | ||
app, | ||
SwaggerModule.createDocument(app, swaggerDocument) | ||
); | ||
await app.listen(3000); | ||
console.log(`APP IS RUNNING ON PORT ${await app.getUrl()}/api`); | ||
} | ||
@@ -47,4 +76,2 @@ bootstrap(); | ||
```typescript | ||
@@ -75,3 +102,3 @@ /* app.controller.ts */ | ||
FilesFastifyInterceptor, | ||
diskStorage | ||
diskStorage, | ||
} from "fastify-file-interceptor"; | ||
@@ -176,3 +203,2 @@ @Controller() | ||
> file-upload-util.ts | ||
@@ -207,6 +233,5 @@ | ||
### Create url display image in browser | ||
#### We use interface FastifyRequest | ||
```javascript | ||
@@ -251,2 +276,3 @@ /* file-mapper.ts */ | ||
### @nestjs/platform-fastify | ||
```typescript | ||
@@ -267,3 +293,2 @@ | ||
[If it useful please give me some star on github :star: :star: :star: :star: :star: ](https://www.google.com) | ||
[If it useful please give me some star on github :star: :star: :star: :star: :star: ](https://www.google.com) |
44936
11
286