@eonasdan/parvus-server
Advanced tools
Comparing version 1.1.9 to 1.2.0
@@ -63,2 +63,3 @@ 'use strict'; | ||
config.middlewares?.forEach(x => this.addMiddleware(x.middleware, x.route)); | ||
this.mimeTypes = config.additionalMimeTypes || []; | ||
} | ||
@@ -68,3 +69,4 @@ } | ||
async startAsync() { | ||
this.mimeTypes = await ParvusServer.fetchMimetypes(); | ||
const mimeTypes = await ParvusServer.fetchMimetypes(); | ||
this.mimeTypes = this.mergedMimeTypes(mimeTypes); | ||
this.createServer(); | ||
@@ -94,2 +96,11 @@ } | ||
} | ||
mergedMimeTypes(mimeTypes) { | ||
return mimeTypes.map(item1 => { | ||
const item2 = this.mimeTypes.find(item => item.type === item1.type); | ||
if (item2) { | ||
return { ...item1, extensions: [...item1.extensions, ...item2.extensions] }; | ||
} | ||
return item1; | ||
}); | ||
} | ||
static async fetchMimetypes() { | ||
@@ -96,0 +107,0 @@ const file = await fs.promises.readFile(`${__dirname}/mime-types.json`, 'utf8'); |
{ | ||
"name": "@eonasdan/parvus-server", | ||
"version": "1.1.9", | ||
"version": "1.2.0", | ||
"description": "", | ||
@@ -8,7 +8,7 @@ "main": "dist/server.js", | ||
"scripts": { | ||
"build": "npm run rollup", | ||
"build": "npm run rollup && node copyToDist.js", | ||
"build:declarations": "tsc --declaration --emitDeclarationOnly --outDir types", | ||
"start": "node example/startup.js", | ||
"start": "npm run build && node example/startup.js", | ||
"rollup": "rollup -c ./rollup.config.js", | ||
"release": "npm run build && npm run build:declarations && node copyToDist.js" | ||
"release": "npm run build && npm run build:declarations" | ||
}, | ||
@@ -15,0 +15,0 @@ "files": [ |
@@ -1,4 +0,3 @@ | ||
import ParvusServer from './parvus-server'; | ||
import { ParvusServer, Config } from './parvus-server'; | ||
import { Next, Stack, Middleware } from './middleware'; | ||
import Config from './config'; | ||
export { ParvusServer, Next, Stack, Middleware, Config }; |
/// <reference types="node" /> | ||
import { Server, IncomingMessage, ServerResponse } from 'http'; | ||
import { Server as Socket } from 'socket.io'; | ||
import { Middleware } from './middleware'; | ||
import Config from './config'; | ||
export default class ParvusServer { | ||
import { Middleware, Stack } from './middleware'; | ||
export interface MimeType { | ||
type: string; | ||
name: string; | ||
extensions: string[]; | ||
} | ||
export interface Config { | ||
host?: string; | ||
port?: number; | ||
subfolder?: string; | ||
middlewares?: Stack[]; | ||
directory?: string; | ||
additionalMimeTypes?: MimeType[]; | ||
} | ||
export declare class ParvusServer { | ||
server: Server; | ||
mimeTypes: { | ||
type: string; | ||
name: string; | ||
extensions: string[]; | ||
}[]; | ||
mimeTypes: MimeType[]; | ||
io: Socket; | ||
@@ -25,2 +33,3 @@ private connectedBefore; | ||
addMiddleware(middleware: Middleware, route?: string): void; | ||
private mergedMimeTypes; | ||
private static fetchMimetypes; | ||
@@ -27,0 +36,0 @@ private createServer; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
114399
5063