Skip to content

Commit

Permalink
Made configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Jan 8, 2022
1 parent c769c85 commit 9ceb5a4
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 0.13.2

- Added configurable file size limit (#50)
- Updated license year

## 0.13.1
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ The `.krasrc` is a simple JSON format. An example is the following configuration
"name": "kras",
"port": 9000,
"directory": ".",
"uploadLimit": 10,
"logLevel": "error",
"ssl": {
"cert": "cert/server.crt",
"key": "cert/server.key"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kras",
"version": "0.13.1",
"version": "0.13.2",
"description": "Efficient server proxying and mocking in Node.js.",
"main": "dist/server/index.js",
"types": "dist/server/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions src/server/core/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export const defaultConfig = {
cert: resolve(rootDir, 'cert', 'server.crt'),
key: resolve(rootDir, 'cert', 'server.key'),
},
uploadLimit: parseInt(process.env.FILE_SIZE_LIMIT, 10) || 10, // default: 10 MB
logLevel: 'error',
api: '/manage',
ws: true,
Expand Down
4 changes: 2 additions & 2 deletions src/server/core/webserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ export class WebServer extends EventEmitter implements BaseKrasServer {
this.server = ssl ? createHttpsServer(ssl, this.app) : createHttpServer(this.app);
this.wsOptions = typeof config.ws === 'object' ? config.ws : undefined;
this.ws = !!config.ws;
const fileSizeLimit = (process.env.FILE_SIZE_LIMIT && parseInt(process.env.FILE_SIZE_LIMIT, 10)) || 10;
const sizeInMB = typeof config.uploadLimit === 'number' ? config.uploadLimit : 10;
const upload = multer({
storage: multer.memoryStorage(),
limits: { files: 5, fileSize: fileSizeLimit * 1024 * 1024 },
limits: { files: 5, fileSize: sizeInMB * 1024 * 1024 },
});
this.app.use(upload.any());
this.app.use(
Expand Down
1 change: 1 addition & 0 deletions src/server/types/kras-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface WebServerConfiguration extends AppConfiguration {
map: WebServerConfigurationMap;
ssl: SslConfiguration;
ws: boolean | Dict<any>;
uploadLimit: number;
port: number;
}

Expand Down

0 comments on commit 9ceb5a4

Please sign in to comment.