Skip to content

Commit

Permalink
feat(server): json body size configuration (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
basmasking authored Mar 5, 2024
1 parent 09f174d commit a5fb2a3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
10 changes: 5 additions & 5 deletions packages/server-nodejs/src/JitarServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ export default class JitarServer
this.#classLoader = new RemoteClassLoader();
this.#serializer = SerializerBuilder.build(this.#classLoader);

this.#options = ServerOptionsReader.read();
this.#configuration = RuntimeConfigurationLoader.load(this.#options.config);
this.#logger = LogBuilder.build(this.#options.loglevel);

this.#app = express();

this.#app.use(express.json());
this.#app.use(express.json({limit: this.#options.bodylimit }));
this.#app.use(express.urlencoded({ extended: true }));
this.#app.use((request, response, next) => this.#addDefaultHeaders(request, response, next));

this.#app.disable('x-powered-by');

this.#options = ServerOptionsReader.read();
this.#configuration = RuntimeConfigurationLoader.load(this.#options.config);
this.#logger = LogBuilder.build(this.#options.loglevel);

this.#printStartupMessage();
}

Expand Down
13 changes: 10 additions & 3 deletions packages/server-nodejs/src/configuration/ServerOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,32 @@
import { z } from 'zod';
import { LogLevel } from '../utils/LogBuilder.js';

const DEFAULT_BODY_LIMIT = 1024 * 200;

export const serverOptionsSchema = z
.object({
loglevel: z.nativeEnum(LogLevel).optional(),
config: z.string().endsWith('.json')
config: z.string().endsWith('.json'),
bodylimit: z.number().positive().optional()
})
.transform((value) => new ServerOptions(value.config, value.loglevel));
.transform((value) => new ServerOptions(value.config, value.loglevel, value.bodylimit));

export default class ServerOptions
{
#config: string;
#loglevel: string;
#bodylimit: number;

constructor(config: string, loglevel = 'info')
constructor(config: string, loglevel = 'info', bodylimit = DEFAULT_BODY_LIMIT)
{
this.#config = config;
this.#loglevel = loglevel;
this.#bodylimit = bodylimit;
}

get config() { return this.#config; }

get loglevel() { return this.#loglevel; }

get bodylimit() { return this.#bodylimit; }
}

0 comments on commit a5fb2a3

Please sign in to comment.