-
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix default export to commonjs export (#78)
- Loading branch information
Showing
2 changed files
with
38 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,46 @@ | ||
import * as fastify from 'fastify' | ||
import fastifyMultipart from '../..' | ||
import fastifyMultipart = require('../..') | ||
|
||
/** TODO This import must be decommented when this | ||
* https://github.com/standard/standard/pull/1101 | ||
* PR will be merged and released | ||
*/ | ||
*/ | ||
// import { Readable } from 'stream' | ||
|
||
const app = fastify() | ||
const runServer = async () => { | ||
const app = fastify() | ||
|
||
app.register(fastifyMultipart, { | ||
addToBody: true, | ||
sharedSchemaId: 'sharedId', | ||
// stream should be of type streams.Readable | ||
// body should be of type fastifyMulipart.Record<string, BodyEntry> | ||
onFile: (fieldName: string, stream: any, filename: string, encoding: string, mimetype: string, body: Record<string, any>) => { | ||
console.log(fieldName, stream, filename, encoding, mimetype, body) | ||
}, | ||
limits: { | ||
fieldNameSize: 200, | ||
fieldSize: 200, | ||
fields: 200, | ||
fileSize: 200, | ||
files: 2, | ||
headerPairs: 200 | ||
} | ||
}) | ||
app.register(fastifyMultipart, { | ||
addToBody: true, | ||
sharedSchemaId: 'sharedId', | ||
// stream should be of type streams.Readable | ||
// body should be of type fastifyMulipart.Record<string, BodyEntry> | ||
onFile: (fieldName: string, stream: any, filename: string, encoding: string, mimetype: string, body: Record<string, any>) => { | ||
console.log(fieldName, stream, filename, encoding, mimetype, body) | ||
}, | ||
limits: { | ||
fieldNameSize: 200, | ||
fieldSize: 200, | ||
fields: 200, | ||
fileSize: 200, | ||
files: 2, | ||
headerPairs: 200 | ||
} | ||
}) | ||
|
||
app.get('/path', (request) => { | ||
const isMultiPart = request.isMultipart() | ||
request.multipart((field, file, filename, encoding, mimetype) => { | ||
console.log(field, file, filename, encoding, mimetype, isMultiPart) | ||
}, (err) => { | ||
throw err | ||
app.get('/path', (request) => { | ||
const isMultiPart = request.isMultipart() | ||
request.multipart((field, file, filename, encoding, mimetype) => { | ||
console.log(field, file, filename, encoding, mimetype, isMultiPart) | ||
}, (err) => { | ||
throw err | ||
}) | ||
}) | ||
}) | ||
|
||
await app.ready() | ||
} | ||
|
||
runServer().then( | ||
console.log.bind(console, 'Success'), | ||
console.error.bind(console, 'Error') | ||
) |