Skip to content

Commit

Permalink
Fix default export to commonjs export (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marsup authored and Eomm committed Jun 25, 2019
1 parent b24dd09 commit 7642182
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 29 deletions.
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type MultipartHandler = (
mimetype: string,
) => void;

export interface BodyEntry {
interface BodyEntry {
data: Buffer,
filename: string,
encoding: string,
Expand Down Expand Up @@ -78,4 +78,4 @@ declare const fastifyMultipart: fastify.Plugin<Server, IncomingMessage, ServerRe
}
}>;

export default fastifyMultipart;
export = fastifyMultipart;
63 changes: 36 additions & 27 deletions test/types/index.ts
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')
)

0 comments on commit 7642182

Please sign in to comment.