@tramvai/module-server 1.92.0 → 1.93.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/server.es.js CHANGED
@@ -9,8 +9,6 @@ import { CacheWarmupModule } from '@tramvai/module-cache-warmup';
9
9
  import http from 'http';
10
10
  import fastify from 'fastify';
11
11
  import express from 'express';
12
- import cookieParser from 'cookie-parser';
13
- import bodyParser from 'body-parser';
14
12
  import { fastifyCookie } from 'fastify-cookie';
15
13
  import fastifyFormBody from 'fastify-formbody';
16
14
  import fp from 'fastify-plugin';
@@ -63,8 +61,8 @@ const expressPlugin = (fastify, options, next) => {
63
61
  fastify.decorate('express', (_b = (_a = options.express) === null || _a === void 0 ? void 0 : _a.instance) !== null && _b !== void 0 ? _b : express());
64
62
  fastify.express.disable('x-powered-by');
65
63
  fastify
66
- .addHook('onRequest', enhanceRequest)
67
- .addHook('onRequest', runConnect)
64
+ .addHook('preHandler', enhanceRequest)
65
+ .addHook('preHandler', runConnect)
68
66
  .addHook('onRegister', onRegister);
69
67
  function use(path, fn) {
70
68
  if (typeof path === 'string') {
@@ -90,6 +88,12 @@ const expressPlugin = (fastify, options, next) => {
90
88
  req.raw.log = req.log;
91
89
  // eslint-disable-next-line no-param-reassign
92
90
  reply.raw.log = req.log;
91
+ if (req.body) {
92
+ req.raw.body = req.body;
93
+ }
94
+ if (req.cookies) {
95
+ req.raw.cookies = req.cookies;
96
+ }
93
97
  const originalProtocol = req.raw.protocol;
94
98
  // Make it lazy as it does a bit of work
95
99
  Object.defineProperty(req.raw, 'protocol', {
@@ -212,11 +216,7 @@ const webAppInitCommand = ({ app, expressApp, logger, commandLineRunner, beforeI
212
216
  await runHandlers(beforeInit, expressBeforeInit);
213
217
  await runHandlers(limiterRequest, expressLimiterRequest);
214
218
  await app.register(fastifyCookie);
215
- await app.register(fastifyFormBody);
216
- expressApp.use(bodyParser.urlencoded({
217
- limit: '2mb',
218
- extended: false,
219
- }), cookieParser());
219
+ await app.register(fastifyFormBody, { bodyLimit: 2097152 }); // 2mb
220
220
  await runHandlers(init, expressInit);
221
221
  // force express to execute to update server's request and response instances
222
222
  app.use((req, res, next) => {
@@ -333,7 +333,6 @@ const xHeadersFactory = ({ app, envManager, appInfo, }) => {
333
333
  function createApi(papiList, { di, logger }) {
334
334
  return create(papiList, [
335
335
  middlewares.timeout(),
336
- middlewares.body(),
337
336
  middlewares.cookie(),
338
337
  middlewares.validate(),
339
338
  middlewares.fillPapiState({
package/lib/server.js CHANGED
@@ -12,8 +12,6 @@ var moduleCacheWarmup = require('@tramvai/module-cache-warmup');
12
12
  var http = require('http');
13
13
  var fastify = require('fastify');
14
14
  var express = require('express');
15
- var cookieParser = require('cookie-parser');
16
- var bodyParser = require('body-parser');
17
15
  var fastifyCookie = require('fastify-cookie');
18
16
  var fastifyFormBody = require('fastify-formbody');
19
17
  var fp = require('fastify-plugin');
@@ -45,8 +43,6 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
45
43
  var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
46
44
  var fastify__default = /*#__PURE__*/_interopDefaultLegacy(fastify);
47
45
  var express__default = /*#__PURE__*/_interopDefaultLegacy(express);
48
- var cookieParser__default = /*#__PURE__*/_interopDefaultLegacy(cookieParser);
49
- var bodyParser__default = /*#__PURE__*/_interopDefaultLegacy(bodyParser);
50
46
  var fastifyFormBody__default = /*#__PURE__*/_interopDefaultLegacy(fastifyFormBody);
51
47
  var fp__default = /*#__PURE__*/_interopDefaultLegacy(fp);
52
48
  var symbols__default = /*#__PURE__*/_interopDefaultLegacy(symbols);
@@ -90,8 +86,8 @@ const expressPlugin = (fastify, options, next) => {
90
86
  fastify.decorate('express', (_b = (_a = options.express) === null || _a === void 0 ? void 0 : _a.instance) !== null && _b !== void 0 ? _b : express__default["default"]());
91
87
  fastify.express.disable('x-powered-by');
92
88
  fastify
93
- .addHook('onRequest', enhanceRequest)
94
- .addHook('onRequest', runConnect)
89
+ .addHook('preHandler', enhanceRequest)
90
+ .addHook('preHandler', runConnect)
95
91
  .addHook('onRegister', onRegister);
96
92
  function use(path, fn) {
97
93
  if (typeof path === 'string') {
@@ -117,6 +113,12 @@ const expressPlugin = (fastify, options, next) => {
117
113
  req.raw.log = req.log;
118
114
  // eslint-disable-next-line no-param-reassign
119
115
  reply.raw.log = req.log;
116
+ if (req.body) {
117
+ req.raw.body = req.body;
118
+ }
119
+ if (req.cookies) {
120
+ req.raw.cookies = req.cookies;
121
+ }
120
122
  const originalProtocol = req.raw.protocol;
121
123
  // Make it lazy as it does a bit of work
122
124
  Object.defineProperty(req.raw, 'protocol', {
@@ -239,11 +241,7 @@ const webAppInitCommand = ({ app, expressApp, logger, commandLineRunner, beforeI
239
241
  await runHandlers(beforeInit, expressBeforeInit);
240
242
  await runHandlers(limiterRequest, expressLimiterRequest);
241
243
  await app.register(fastifyCookie.fastifyCookie);
242
- await app.register(fastifyFormBody__default["default"]);
243
- expressApp.use(bodyParser__default["default"].urlencoded({
244
- limit: '2mb',
245
- extended: false,
246
- }), cookieParser__default["default"]());
244
+ await app.register(fastifyFormBody__default["default"], { bodyLimit: 2097152 }); // 2mb
247
245
  await runHandlers(init, expressInit);
248
246
  // force express to execute to update server's request and response instances
249
247
  app.use((req, res, next) => {
@@ -360,7 +358,6 @@ const xHeadersFactory = ({ app, envManager, appInfo, }) => {
360
358
  function createApi(papiList, { di, logger }) {
361
359
  return papi.create(papiList, [
362
360
  papi.middlewares.timeout(),
363
- papi.middlewares.body(),
364
361
  papi.middlewares.cookie(),
365
362
  papi.middlewares.validate(),
366
363
  papi.middlewares.fillPapiState({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-server",
3
- "version": "1.92.0",
3
+ "version": "1.93.1",
4
4
  "description": "",
5
5
  "browser": "lib/browser.js",
6
6
  "main": "lib/server.js",
@@ -23,14 +23,12 @@
23
23
  "@tinkoff/monkeypatch": "1.3.3",
24
24
  "@tinkoff/terminus": "0.0.1",
25
25
  "@tinkoff/url": "0.7.37",
26
- "@tramvai/module-cache-warmup": "1.92.0",
27
- "@tramvai/module-metrics": "1.92.0",
28
- "@tramvai/papi": "1.92.0",
29
- "@tramvai/tokens-server": "1.92.0",
30
- "@tramvai/tokens-server-private": "1.92.0",
31
- "body-parser": "^1.19.0",
26
+ "@tramvai/module-cache-warmup": "1.93.1",
27
+ "@tramvai/module-metrics": "1.93.1",
28
+ "@tramvai/papi": "1.93.1",
29
+ "@tramvai/tokens-server": "1.93.1",
30
+ "@tramvai/tokens-server-private": "1.93.1",
32
31
  "compression": "^1.7.4",
33
- "cookie-parser": "^1.4.3",
34
32
  "express": "^4.17.1",
35
33
  "fastify": "^3.27.4",
36
34
  "fastify-cookie": "^5.6.0",
@@ -42,11 +40,11 @@
42
40
  "peerDependencies": {
43
41
  "@tinkoff/dippy": "0.7.39",
44
42
  "@tinkoff/utils": "^2.1.2",
45
- "@tramvai/cli": "1.92.0",
46
- "@tramvai/core": "1.92.0",
47
- "@tramvai/module-common": "1.92.0",
48
- "@tramvai/module-environment": "1.92.0",
49
- "@tramvai/tokens-common": "1.92.0",
43
+ "@tramvai/cli": "1.93.1",
44
+ "@tramvai/core": "1.93.1",
45
+ "@tramvai/module-common": "1.93.1",
46
+ "@tramvai/module-environment": "1.93.1",
47
+ "@tramvai/tokens-common": "1.93.1",
50
48
  "tslib": "^2.0.3"
51
49
  },
52
50
  "devDependencies": {