@lark-apaas/fullstack-nestjs-core 1.1.24-alpha.26 → 1.1.24-alpha.28

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/dist/index.cjs CHANGED
@@ -32978,18 +32978,18 @@ __export(index_exports, {
32978
32978
  DevToolsModule: () => import_nestjs_openapi_devtools2.DevToolsModule,
32979
32979
  DevToolsV2Module: () => import_nestjs_openapi_devtools2.DevToolsV2Module,
32980
32980
  FileService: () => FileService,
32981
- LegacyPathRedirectMiddleware: () => LegacyPathRedirectMiddleware,
32982
32981
  PlatformHttpClientService: () => PlatformHttpClientService,
32983
32982
  PlatformModule: () => PlatformModule,
32984
32983
  StaticModule: () => StaticModule,
32985
32984
  UserContextMiddleware: () => UserContextMiddleware,
32986
32985
  ViewContextMiddleware: () => ViewContextMiddleware,
32987
- configureApp: () => configureApp
32986
+ configureApp: () => configureApp,
32987
+ createLegacyPathRedirectMiddleware: () => createLegacyPathRedirectMiddleware
32988
32988
  });
32989
32989
  module.exports = __toCommonJS(index_exports);
32990
32990
 
32991
32991
  // src/modules/platform/module.ts
32992
- var import_common13 = require("@nestjs/common");
32992
+ var import_common12 = require("@nestjs/common");
32993
32993
  var import_core2 = require("@nestjs/core");
32994
32994
  var import_nestjs_common5 = require("@lark-apaas/nestjs-common");
32995
32995
  var import_config2 = require("@nestjs/config");
@@ -33570,59 +33570,17 @@ FrameworkDebugMiddleware = _ts_decorate7([
33570
33570
  ])
33571
33571
  ], FrameworkDebugMiddleware);
33572
33572
 
33573
- // src/middlewares/legacy-path-redirect/index.ts
33574
- var import_common8 = require("@nestjs/common");
33575
- function _ts_decorate8(decorators, target, key, desc) {
33576
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
33577
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
33578
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
33579
- return c > 3 && r && Object.defineProperty(target, key, r), r;
33580
- }
33581
- __name(_ts_decorate8, "_ts_decorate");
33582
- var OLD_PATH_PREFIX = {
33583
- preview: "/af/p",
33584
- runtime: "/spark/faas"
33585
- };
33586
- var LegacyPathRedirectMiddleware = class {
33587
- static {
33588
- __name(this, "LegacyPathRedirectMiddleware");
33589
- }
33590
- use(req, res, next) {
33591
- const basePath = process.env.CLIENT_BASE_PATH ?? "";
33592
- if (!/^\/app\/[^/]/.test(basePath)) {
33593
- return next();
33594
- }
33595
- if (req.path.startsWith("/api")) {
33596
- return next();
33597
- }
33598
- const { appId, env } = req.userContext ?? {};
33599
- if (!appId || !env) {
33600
- return next();
33601
- }
33602
- const oldPrefix = `${OLD_PATH_PREFIX[env]}/${appId}`;
33603
- if (!req.path.startsWith(oldPrefix)) {
33604
- return next();
33605
- }
33606
- const pathSuffix = req.path.slice(oldPrefix.length) || "/";
33607
- const querySuffix = req.originalUrl.slice(req.path.length);
33608
- return res.redirect(302, `${basePath}${pathSuffix}${querySuffix}`);
33609
- }
33610
- };
33611
- LegacyPathRedirectMiddleware = _ts_decorate8([
33612
- (0, import_common8.Injectable)()
33613
- ], LegacyPathRedirectMiddleware);
33614
-
33615
33573
  // src/services/platform-http-client.service.ts
33616
- var import_common9 = require("@nestjs/common");
33574
+ var import_common8 = require("@nestjs/common");
33617
33575
  var import_http_client = require("@lark-apaas/http-client");
33618
33576
  var import_nestjs_common3 = require("@lark-apaas/nestjs-common");
33619
- function _ts_decorate9(decorators, target, key, desc) {
33577
+ function _ts_decorate8(decorators, target, key, desc) {
33620
33578
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
33621
33579
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
33622
33580
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
33623
33581
  return c > 3 && r && Object.defineProperty(target, key, r), r;
33624
33582
  }
33625
- __name(_ts_decorate9, "_ts_decorate");
33583
+ __name(_ts_decorate8, "_ts_decorate");
33626
33584
  function _ts_metadata5(k, v) {
33627
33585
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
33628
33586
  }
@@ -33661,7 +33619,7 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
33661
33619
  requestContext;
33662
33620
  client;
33663
33621
  protectedClient;
33664
- logger = new import_common9.Logger(_PlatformHttpClientService.name);
33622
+ logger = new import_common8.Logger(_PlatformHttpClientService.name);
33665
33623
  constructor(requestContext) {
33666
33624
  this.requestContext = requestContext;
33667
33625
  const baseConfig = {
@@ -33817,8 +33775,8 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
33817
33775
  });
33818
33776
  }
33819
33777
  };
33820
- PlatformHttpClientService = _ts_decorate9([
33821
- (0, import_common9.Injectable)(),
33778
+ PlatformHttpClientService = _ts_decorate8([
33779
+ (0, import_common8.Injectable)(),
33822
33780
  _ts_metadata5("design:type", Function),
33823
33781
  _ts_metadata5("design:paramtypes", [
33824
33782
  typeof import_nestjs_common3.RequestContextService === "undefined" ? Object : import_nestjs_common3.RequestContextService
@@ -33829,16 +33787,16 @@ PlatformHttpClientService = _ts_decorate9([
33829
33787
  var DISABLE_DATAPASS = process.env.FORCE_FRAMEWORK_DISABLE_DATAPASS === "true";
33830
33788
 
33831
33789
  // src/services/file.service.ts
33832
- var import_common10 = require("@nestjs/common");
33790
+ var import_common9 = require("@nestjs/common");
33833
33791
  var import_nestjs_common4 = require("@lark-apaas/nestjs-common");
33834
33792
  var import_file_service = require("@lark-apaas/file-service");
33835
- function _ts_decorate10(decorators, target, key, desc) {
33793
+ function _ts_decorate9(decorators, target, key, desc) {
33836
33794
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
33837
33795
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
33838
33796
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
33839
33797
  return c > 3 && r && Object.defineProperty(target, key, r), r;
33840
33798
  }
33841
- __name(_ts_decorate10, "_ts_decorate");
33799
+ __name(_ts_decorate9, "_ts_decorate");
33842
33800
  function _ts_metadata6(k, v) {
33843
33801
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
33844
33802
  }
@@ -33863,7 +33821,7 @@ var FileService = class {
33863
33821
  this.httpClient = httpClient;
33864
33822
  this.observable = observable;
33865
33823
  this.fileServiceCore = new import_file_service.FileService(this.httpClient);
33866
- this.nestLogger = new import_common10.Logger("file");
33824
+ this.nestLogger = new import_common9.Logger("file");
33867
33825
  }
33868
33826
  /**
33869
33827
  * 返回一个绑定了指定 bucket 的代理对象
@@ -34203,10 +34161,10 @@ var FileService = class {
34203
34161
  }
34204
34162
  }
34205
34163
  };
34206
- FileService = _ts_decorate10([
34207
- (0, import_common10.Injectable)(),
34208
- _ts_param2(1, (0, import_common10.Inject)(import_nestjs_common4.PLATFORM_HTTP_CLIENT)),
34209
- _ts_param2(2, (0, import_common10.Inject)(import_nestjs_common4.OBSERVABLE_SERVICE)),
34164
+ FileService = _ts_decorate9([
34165
+ (0, import_common9.Injectable)(),
34166
+ _ts_param2(1, (0, import_common9.Inject)(import_nestjs_common4.PLATFORM_HTTP_CLIENT)),
34167
+ _ts_param2(2, (0, import_common9.Inject)(import_nestjs_common4.OBSERVABLE_SERVICE)),
34210
34168
  _ts_metadata6("design:type", Function),
34211
34169
  _ts_metadata6("design:paramtypes", [
34212
34170
  typeof import_nestjs_common4.RequestContextService === "undefined" ? Object : import_nestjs_common4.RequestContextService,
@@ -34219,21 +34177,21 @@ FileService = _ts_decorate10([
34219
34177
  var import_nestjs_authzpaas = require("@lark-apaas/nestjs-authzpaas");
34220
34178
 
34221
34179
  // src/modules/static/static.module.ts
34222
- var import_common12 = require("@nestjs/common");
34180
+ var import_common11 = require("@nestjs/common");
34223
34181
 
34224
34182
  // src/modules/static/static.controller.ts
34225
- var import_common11 = require("@nestjs/common");
34183
+ var import_common10 = require("@nestjs/common");
34226
34184
  var import_swagger = require("@nestjs/swagger");
34227
34185
  var fs = __toESM(require("fs"), 1);
34228
34186
  var path = __toESM(require("path"), 1);
34229
34187
  var crypto2 = __toESM(require("crypto"), 1);
34230
- function _ts_decorate11(decorators, target, key, desc) {
34188
+ function _ts_decorate10(decorators, target, key, desc) {
34231
34189
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
34232
34190
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
34233
34191
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
34234
34192
  return c > 3 && r && Object.defineProperty(target, key, r), r;
34235
34193
  }
34236
- __name(_ts_decorate11, "_ts_decorate");
34194
+ __name(_ts_decorate10, "_ts_decorate");
34237
34195
  function _ts_metadata7(k, v) {
34238
34196
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
34239
34197
  }
@@ -34301,7 +34259,7 @@ var StaticController = class _StaticController {
34301
34259
  static {
34302
34260
  __name(this, "StaticController");
34303
34261
  }
34304
- logger = new import_common11.Logger(_StaticController.name);
34262
+ logger = new import_common10.Logger(_StaticController.name);
34305
34263
  staticDir;
34306
34264
  constructor() {
34307
34265
  this.staticDir = path.resolve(process.cwd(), "../shared/static");
@@ -34322,7 +34280,7 @@ var StaticController = class _StaticController {
34322
34280
  try {
34323
34281
  const relativePath = params["0"] || params["*"] || "";
34324
34282
  if (!relativePath) {
34325
- res.status(import_common11.HttpStatus.BAD_REQUEST).json({
34283
+ res.status(import_common10.HttpStatus.BAD_REQUEST).json({
34326
34284
  error: "Bad Request",
34327
34285
  message: "File path is required"
34328
34286
  });
@@ -34332,14 +34290,14 @@ var StaticController = class _StaticController {
34332
34290
  const normalizedPath = path.normalize(filePath);
34333
34291
  if (!normalizedPath.startsWith(this.staticDir)) {
34334
34292
  this.logger.warn(`Path traversal attempt detected: ${relativePath}`);
34335
- res.status(import_common11.HttpStatus.FORBIDDEN).json({
34293
+ res.status(import_common10.HttpStatus.FORBIDDEN).json({
34336
34294
  error: "Forbidden",
34337
34295
  message: "Access denied"
34338
34296
  });
34339
34297
  return;
34340
34298
  }
34341
34299
  if (!fs.existsSync(normalizedPath)) {
34342
- res.status(import_common11.HttpStatus.NOT_FOUND).json({
34300
+ res.status(import_common10.HttpStatus.NOT_FOUND).json({
34343
34301
  error: "Not Found",
34344
34302
  message: "File not found"
34345
34303
  });
@@ -34347,7 +34305,7 @@ var StaticController = class _StaticController {
34347
34305
  }
34348
34306
  const stat = fs.statSync(normalizedPath);
34349
34307
  if (stat.isDirectory()) {
34350
- res.status(import_common11.HttpStatus.FORBIDDEN).json({
34308
+ res.status(import_common10.HttpStatus.FORBIDDEN).json({
34351
34309
  error: "Forbidden",
34352
34310
  message: "Directory listing not allowed"
34353
34311
  });
@@ -34357,7 +34315,7 @@ var StaticController = class _StaticController {
34357
34315
  const etag = generateETag(stat);
34358
34316
  const ifNoneMatch = req.headers["if-none-match"];
34359
34317
  if (ifNoneMatch === etag) {
34360
- res.status(import_common11.HttpStatus.NOT_MODIFIED).end();
34318
+ res.status(import_common10.HttpStatus.NOT_MODIFIED).end();
34361
34319
  return;
34362
34320
  }
34363
34321
  res.setHeader("Content-Type", mimeType);
@@ -34368,7 +34326,7 @@ var StaticController = class _StaticController {
34368
34326
  stream.on("error", (error) => {
34369
34327
  this.logger.error(`Error streaming file: ${relativePath}`, error);
34370
34328
  if (!res.headersSent) {
34371
- res.status(import_common11.HttpStatus.INTERNAL_SERVER_ERROR).json({
34329
+ res.status(import_common10.HttpStatus.INTERNAL_SERVER_ERROR).json({
34372
34330
  error: "Internal Server Error",
34373
34331
  message: "Failed to read file"
34374
34332
  });
@@ -34378,7 +34336,7 @@ var StaticController = class _StaticController {
34378
34336
  } catch (error) {
34379
34337
  this.logger.error("Error serving static file", error);
34380
34338
  if (!res.headersSent) {
34381
- res.status(import_common11.HttpStatus.INTERNAL_SERVER_ERROR).json({
34339
+ res.status(import_common10.HttpStatus.INTERNAL_SERVER_ERROR).json({
34382
34340
  error: "Internal Server Error",
34383
34341
  message: "An unexpected error occurred"
34384
34342
  });
@@ -34386,11 +34344,11 @@ var StaticController = class _StaticController {
34386
34344
  }
34387
34345
  }
34388
34346
  };
34389
- _ts_decorate11([
34390
- (0, import_common11.Get)("*"),
34391
- _ts_param3(0, (0, import_common11.Param)()),
34392
- _ts_param3(1, (0, import_common11.Req)()),
34393
- _ts_param3(2, (0, import_common11.Res)()),
34347
+ _ts_decorate10([
34348
+ (0, import_common10.Get)("*"),
34349
+ _ts_param3(0, (0, import_common10.Param)()),
34350
+ _ts_param3(1, (0, import_common10.Req)()),
34351
+ _ts_param3(2, (0, import_common10.Res)()),
34394
34352
  _ts_metadata7("design:type", Function),
34395
34353
  _ts_metadata7("design:paramtypes", [
34396
34354
  typeof Record === "undefined" ? Object : Record,
@@ -34399,28 +34357,28 @@ _ts_decorate11([
34399
34357
  ]),
34400
34358
  _ts_metadata7("design:returntype", void 0)
34401
34359
  ], StaticController.prototype, "serveFile", null);
34402
- StaticController = _ts_decorate11([
34360
+ StaticController = _ts_decorate10([
34403
34361
  (0, import_swagger.ApiExcludeController)(),
34404
- (0, import_common11.Controller)("static"),
34362
+ (0, import_common10.Controller)("static"),
34405
34363
  _ts_metadata7("design:type", Function),
34406
34364
  _ts_metadata7("design:paramtypes", [])
34407
34365
  ], StaticController);
34408
34366
 
34409
34367
  // src/modules/static/static.module.ts
34410
- function _ts_decorate12(decorators, target, key, desc) {
34368
+ function _ts_decorate11(decorators, target, key, desc) {
34411
34369
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
34412
34370
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
34413
34371
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
34414
34372
  return c > 3 && r && Object.defineProperty(target, key, r), r;
34415
34373
  }
34416
- __name(_ts_decorate12, "_ts_decorate");
34374
+ __name(_ts_decorate11, "_ts_decorate");
34417
34375
  var StaticModule = class {
34418
34376
  static {
34419
34377
  __name(this, "StaticModule");
34420
34378
  }
34421
34379
  };
34422
- StaticModule = _ts_decorate12([
34423
- (0, import_common12.Module)({
34380
+ StaticModule = _ts_decorate11([
34381
+ (0, import_common11.Module)({
34424
34382
  controllers: [
34425
34383
  StaticController
34426
34384
  ]
@@ -34428,13 +34386,13 @@ StaticModule = _ts_decorate12([
34428
34386
  ], StaticModule);
34429
34387
 
34430
34388
  // src/modules/platform/module.ts
34431
- function _ts_decorate13(decorators, target, key, desc) {
34389
+ function _ts_decorate12(decorators, target, key, desc) {
34432
34390
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
34433
34391
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
34434
34392
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
34435
34393
  return c > 3 && r && Object.defineProperty(target, key, r), r;
34436
34394
  }
34437
- __name(_ts_decorate13, "_ts_decorate");
34395
+ __name(_ts_decorate12, "_ts_decorate");
34438
34396
  var PLATFORM_MODULE_OPTIONS = /* @__PURE__ */ Symbol("PLATFORM_MODULE_OPTIONS");
34439
34397
  var PlatformModule = class _PlatformModule {
34440
34398
  static {
@@ -34514,7 +34472,7 @@ var PlatformModule = class _PlatformModule {
34514
34472
  },
34515
34473
  {
34516
34474
  provide: import_core2.APP_PIPE,
34517
- useValue: new import_common13.ValidationPipe({
34475
+ useValue: new import_common12.ValidationPipe({
34518
34476
  transform: true,
34519
34477
  transformOptions: {
34520
34478
  enableImplicitConversion: true
@@ -34574,7 +34532,6 @@ var PlatformModule = class _PlatformModule {
34574
34532
  consumer.apply(UserContextMiddleware, RequestContextMiddleware, import_nestjs_logger2.LoggerContextMiddleware, import_nestjs_observable.ObservableTraceMiddleware, ...DISABLE_DATAPASS ? [] : [
34575
34533
  import_nestjs_datapaas.SqlExecutionContextMiddleware
34576
34534
  ]).forRoutes("/*");
34577
- consumer.apply(LegacyPathRedirectMiddleware).forRoutes("/*");
34578
34535
  consumer.apply(CsrfTokenMiddleware, ViewContextMiddleware).exclude("/api/(.*)", "/static/(.*)").forRoutes("*");
34579
34536
  if (options.enableCsrf !== false) {
34580
34537
  const csrfRoutes = options.csrfRoutes || "/api/*";
@@ -34588,9 +34545,9 @@ var PlatformModule = class _PlatformModule {
34588
34545
  }
34589
34546
  }
34590
34547
  };
34591
- PlatformModule = _ts_decorate13([
34592
- (0, import_common13.Global)(),
34593
- (0, import_common13.Module)({})
34548
+ PlatformModule = _ts_decorate12([
34549
+ (0, import_common12.Global)(),
34550
+ (0, import_common12.Module)({})
34594
34551
  ], PlatformModule);
34595
34552
 
34596
34553
  // src/setup.ts
@@ -34598,6 +34555,43 @@ var import_nestjs_logger3 = require("@lark-apaas/nestjs-logger");
34598
34555
  var import_cookie_parser = __toESM(require("cookie-parser"), 1);
34599
34556
  var import_express = __toESM(require_express2(), 1);
34600
34557
  var import_nestjs_openapi_devtools = require("@lark-apaas/nestjs-openapi-devtools");
34558
+
34559
+ // src/middlewares/legacy-path-redirect/index.ts
34560
+ var LEGACY_ROUTE_PATTERNS = [
34561
+ /^\/af\/p\/([^/]+)(\/.*)?$/,
34562
+ /^\/spark\/faas\/([^/]+)(\/.*)?$/
34563
+ ];
34564
+ function createLegacyPathRedirectMiddleware() {
34565
+ return (req, res, next) => {
34566
+ const basePath = process.env.CLIENT_BASE_PATH ?? "";
34567
+ if (!/^\/app\/[^/]/.test(basePath)) {
34568
+ return next();
34569
+ }
34570
+ for (const pattern of LEGACY_ROUTE_PATTERNS) {
34571
+ const match = req.path.match(pattern);
34572
+ if (match) {
34573
+ const appId = match[1];
34574
+ const suffix = match[2] || "/";
34575
+ const querySuffix = req.originalUrl.slice(req.path.length);
34576
+ const normalized = basePath.replace(/\/+$/, "");
34577
+ const basePrefix = normalized.slice(0, normalized.lastIndexOf("/"));
34578
+ const newUrl = `${basePrefix}/${appId}${suffix}${querySuffix}`;
34579
+ if (suffix.startsWith("/api/") || suffix.startsWith("/__innerapi__/")) {
34580
+ req.url = newUrl;
34581
+ return next();
34582
+ }
34583
+ if (req.method === "GET") {
34584
+ return res.redirect(302, newUrl);
34585
+ }
34586
+ return next();
34587
+ }
34588
+ }
34589
+ return next();
34590
+ };
34591
+ }
34592
+ __name(createLegacyPathRedirectMiddleware, "createLegacyPathRedirectMiddleware");
34593
+
34594
+ // src/setup.ts
34601
34595
  var DEFAULT_BODY_LIMIT = "1mb";
34602
34596
  var defaultPerms = {
34603
34597
  disableSwagger: false
@@ -34614,6 +34608,7 @@ async function configureApp(app, perms = defaultPerms) {
34614
34608
  extended: true
34615
34609
  }));
34616
34610
  app.use((0, import_cookie_parser.default)());
34611
+ app.use(createLegacyPathRedirectMiddleware());
34617
34612
  const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
34618
34613
  app.setGlobalPrefix(globalPrefix);
34619
34614
  app.set("trust proxy", true);
@@ -34651,13 +34646,13 @@ var import_nestjs_authzpaas2 = require("@lark-apaas/nestjs-authzpaas");
34651
34646
  DevToolsModule,
34652
34647
  DevToolsV2Module,
34653
34648
  FileService,
34654
- LegacyPathRedirectMiddleware,
34655
34649
  PlatformHttpClientService,
34656
34650
  PlatformModule,
34657
34651
  StaticModule,
34658
34652
  UserContextMiddleware,
34659
34653
  ViewContextMiddleware,
34660
34654
  configureApp,
34655
+ createLegacyPathRedirectMiddleware,
34661
34656
  ...require("@lark-apaas/nestjs-authnpaas"),
34662
34657
  ...require("@lark-apaas/nestjs-capability"),
34663
34658
  ...require("@lark-apaas/nestjs-datapaas"),
package/dist/index.d.cts CHANGED
@@ -159,18 +159,20 @@ declare class ViewContextMiddleware implements NestMiddleware {
159
159
  }
160
160
 
161
161
  /**
162
- * 旧路径兼容重定向中间件
162
+ * 创建旧路径兼容中间件(纯 Express 中间件)。
163
163
  *
164
- * 当 CLIENT_BASE_PATH 切换到新的 /app/:appId 格式后,
165
- * 将旧路径的页面请求重定向到新路径,实现平滑过渡:
164
+ * 当 CLIENT_BASE_PATH 为新的 /app/:appId 格式时,
165
+ * 将旧路径请求映射到新路径:
166
166
  * 预览态:/af/p/:appId/... → /app/:appId/...
167
167
  * 运行态:/spark/faas/:appId/... → /app/:appId/...
168
168
  *
169
- * 依赖 UserContextMiddleware 已在前置链中填充 req.userContext。
169
+ * 处理策略:
170
+ * - API 路由(/api/)及内部路由(/__innerapi__/):URL rewrite,保留 HTTP 方法和请求体
171
+ * - 页面导航(GET 其他路径):302 重定向,更新浏览器地址栏
172
+ *
173
+ * 不依赖 req.userContext,直接通过正则从 URL 解析 appId。
170
174
  */
171
- declare class LegacyPathRedirectMiddleware implements NestMiddleware {
172
- use(req: Request, res: Response, next: NextFunction): void;
173
- }
175
+ declare function createLegacyPathRedirectMiddleware(): (req: Request, res: Response, next: NextFunction) => void;
174
176
 
175
177
  /**
176
178
  * API 404 响应格式
@@ -352,4 +354,4 @@ declare class PlatformHttpClientService {
352
354
  private registerInterceptorsForClient;
353
355
  }
354
356
 
355
- export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, FileService, LegacyPathRedirectMiddleware, type PlatformHttpClientOptions, PlatformHttpClientService, PlatformModule, type PlatformModuleOptions, StaticModule, UserContextMiddleware, ViewContextMiddleware, configureApp };
357
+ export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, FileService, type PlatformHttpClientOptions, PlatformHttpClientService, PlatformModule, type PlatformModuleOptions, StaticModule, UserContextMiddleware, ViewContextMiddleware, configureApp, createLegacyPathRedirectMiddleware };
package/dist/index.d.ts CHANGED
@@ -159,18 +159,20 @@ declare class ViewContextMiddleware implements NestMiddleware {
159
159
  }
160
160
 
161
161
  /**
162
- * 旧路径兼容重定向中间件
162
+ * 创建旧路径兼容中间件(纯 Express 中间件)。
163
163
  *
164
- * 当 CLIENT_BASE_PATH 切换到新的 /app/:appId 格式后,
165
- * 将旧路径的页面请求重定向到新路径,实现平滑过渡:
164
+ * 当 CLIENT_BASE_PATH 为新的 /app/:appId 格式时,
165
+ * 将旧路径请求映射到新路径:
166
166
  * 预览态:/af/p/:appId/... → /app/:appId/...
167
167
  * 运行态:/spark/faas/:appId/... → /app/:appId/...
168
168
  *
169
- * 依赖 UserContextMiddleware 已在前置链中填充 req.userContext。
169
+ * 处理策略:
170
+ * - API 路由(/api/)及内部路由(/__innerapi__/):URL rewrite,保留 HTTP 方法和请求体
171
+ * - 页面导航(GET 其他路径):302 重定向,更新浏览器地址栏
172
+ *
173
+ * 不依赖 req.userContext,直接通过正则从 URL 解析 appId。
170
174
  */
171
- declare class LegacyPathRedirectMiddleware implements NestMiddleware {
172
- use(req: Request, res: Response, next: NextFunction): void;
173
- }
175
+ declare function createLegacyPathRedirectMiddleware(): (req: Request, res: Response, next: NextFunction) => void;
174
176
 
175
177
  /**
176
178
  * API 404 响应格式
@@ -352,4 +354,4 @@ declare class PlatformHttpClientService {
352
354
  private registerInterceptorsForClient;
353
355
  }
354
356
 
355
- export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, FileService, LegacyPathRedirectMiddleware, type PlatformHttpClientOptions, PlatformHttpClientService, PlatformModule, type PlatformModuleOptions, StaticModule, UserContextMiddleware, ViewContextMiddleware, configureApp };
357
+ export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, FileService, type PlatformHttpClientOptions, PlatformHttpClientService, PlatformModule, type PlatformModuleOptions, StaticModule, UserContextMiddleware, ViewContextMiddleware, configureApp, createLegacyPathRedirectMiddleware };
package/dist/index.js CHANGED
@@ -33549,59 +33549,17 @@ FrameworkDebugMiddleware = _ts_decorate7([
33549
33549
  ])
33550
33550
  ], FrameworkDebugMiddleware);
33551
33551
 
33552
- // src/middlewares/legacy-path-redirect/index.ts
33553
- import { Injectable as Injectable8 } from "@nestjs/common";
33554
- function _ts_decorate8(decorators, target, key, desc) {
33555
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
33556
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
33557
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
33558
- return c > 3 && r && Object.defineProperty(target, key, r), r;
33559
- }
33560
- __name(_ts_decorate8, "_ts_decorate");
33561
- var OLD_PATH_PREFIX = {
33562
- preview: "/af/p",
33563
- runtime: "/spark/faas"
33564
- };
33565
- var LegacyPathRedirectMiddleware = class {
33566
- static {
33567
- __name(this, "LegacyPathRedirectMiddleware");
33568
- }
33569
- use(req, res, next) {
33570
- const basePath = process.env.CLIENT_BASE_PATH ?? "";
33571
- if (!/^\/app\/[^/]/.test(basePath)) {
33572
- return next();
33573
- }
33574
- if (req.path.startsWith("/api")) {
33575
- return next();
33576
- }
33577
- const { appId, env } = req.userContext ?? {};
33578
- if (!appId || !env) {
33579
- return next();
33580
- }
33581
- const oldPrefix = `${OLD_PATH_PREFIX[env]}/${appId}`;
33582
- if (!req.path.startsWith(oldPrefix)) {
33583
- return next();
33584
- }
33585
- const pathSuffix = req.path.slice(oldPrefix.length) || "/";
33586
- const querySuffix = req.originalUrl.slice(req.path.length);
33587
- return res.redirect(302, `${basePath}${pathSuffix}${querySuffix}`);
33588
- }
33589
- };
33590
- LegacyPathRedirectMiddleware = _ts_decorate8([
33591
- Injectable8()
33592
- ], LegacyPathRedirectMiddleware);
33593
-
33594
33552
  // src/services/platform-http-client.service.ts
33595
- import { Injectable as Injectable9, Logger as Logger2 } from "@nestjs/common";
33553
+ import { Injectable as Injectable8, Logger as Logger2 } from "@nestjs/common";
33596
33554
  import { HttpClient } from "@lark-apaas/http-client";
33597
33555
  import { RequestContextService as RequestContextService2 } from "@lark-apaas/nestjs-common";
33598
- function _ts_decorate9(decorators, target, key, desc) {
33556
+ function _ts_decorate8(decorators, target, key, desc) {
33599
33557
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
33600
33558
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
33601
33559
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
33602
33560
  return c > 3 && r && Object.defineProperty(target, key, r), r;
33603
33561
  }
33604
- __name(_ts_decorate9, "_ts_decorate");
33562
+ __name(_ts_decorate8, "_ts_decorate");
33605
33563
  function _ts_metadata5(k, v) {
33606
33564
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
33607
33565
  }
@@ -33796,8 +33754,8 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
33796
33754
  });
33797
33755
  }
33798
33756
  };
33799
- PlatformHttpClientService = _ts_decorate9([
33800
- Injectable9(),
33757
+ PlatformHttpClientService = _ts_decorate8([
33758
+ Injectable8(),
33801
33759
  _ts_metadata5("design:type", Function),
33802
33760
  _ts_metadata5("design:paramtypes", [
33803
33761
  typeof RequestContextService2 === "undefined" ? Object : RequestContextService2
@@ -33808,16 +33766,16 @@ PlatformHttpClientService = _ts_decorate9([
33808
33766
  var DISABLE_DATAPASS = process.env.FORCE_FRAMEWORK_DISABLE_DATAPASS === "true";
33809
33767
 
33810
33768
  // src/services/file.service.ts
33811
- import { Injectable as Injectable10, Inject as Inject2, Logger as Logger3 } from "@nestjs/common";
33769
+ import { Injectable as Injectable9, Inject as Inject2, Logger as Logger3 } from "@nestjs/common";
33812
33770
  import { ObservableService, RequestContextService as RequestContextService3, PLATFORM_HTTP_CLIENT as PLATFORM_HTTP_CLIENT2, OBSERVABLE_SERVICE } from "@lark-apaas/nestjs-common";
33813
33771
  import { FileService as FileServiceCore, FileDownloadBuilder } from "@lark-apaas/file-service";
33814
- function _ts_decorate10(decorators, target, key, desc) {
33772
+ function _ts_decorate9(decorators, target, key, desc) {
33815
33773
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
33816
33774
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
33817
33775
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
33818
33776
  return c > 3 && r && Object.defineProperty(target, key, r), r;
33819
33777
  }
33820
- __name(_ts_decorate10, "_ts_decorate");
33778
+ __name(_ts_decorate9, "_ts_decorate");
33821
33779
  function _ts_metadata6(k, v) {
33822
33780
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
33823
33781
  }
@@ -34182,8 +34140,8 @@ var FileService = class {
34182
34140
  }
34183
34141
  }
34184
34142
  };
34185
- FileService = _ts_decorate10([
34186
- Injectable10(),
34143
+ FileService = _ts_decorate9([
34144
+ Injectable9(),
34187
34145
  _ts_param2(1, Inject2(PLATFORM_HTTP_CLIENT2)),
34188
34146
  _ts_param2(2, Inject2(OBSERVABLE_SERVICE)),
34189
34147
  _ts_metadata6("design:type", Function),
@@ -34206,13 +34164,13 @@ import { ApiExcludeController } from "@nestjs/swagger";
34206
34164
  import * as fs from "fs";
34207
34165
  import * as path from "path";
34208
34166
  import * as crypto2 from "crypto";
34209
- function _ts_decorate11(decorators, target, key, desc) {
34167
+ function _ts_decorate10(decorators, target, key, desc) {
34210
34168
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
34211
34169
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
34212
34170
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
34213
34171
  return c > 3 && r && Object.defineProperty(target, key, r), r;
34214
34172
  }
34215
- __name(_ts_decorate11, "_ts_decorate");
34173
+ __name(_ts_decorate10, "_ts_decorate");
34216
34174
  function _ts_metadata7(k, v) {
34217
34175
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
34218
34176
  }
@@ -34365,7 +34323,7 @@ var StaticController = class _StaticController {
34365
34323
  }
34366
34324
  }
34367
34325
  };
34368
- _ts_decorate11([
34326
+ _ts_decorate10([
34369
34327
  Get("*"),
34370
34328
  _ts_param3(0, Param()),
34371
34329
  _ts_param3(1, Req()),
@@ -34378,7 +34336,7 @@ _ts_decorate11([
34378
34336
  ]),
34379
34337
  _ts_metadata7("design:returntype", void 0)
34380
34338
  ], StaticController.prototype, "serveFile", null);
34381
- StaticController = _ts_decorate11([
34339
+ StaticController = _ts_decorate10([
34382
34340
  ApiExcludeController(),
34383
34341
  Controller("static"),
34384
34342
  _ts_metadata7("design:type", Function),
@@ -34386,19 +34344,19 @@ StaticController = _ts_decorate11([
34386
34344
  ], StaticController);
34387
34345
 
34388
34346
  // src/modules/static/static.module.ts
34389
- function _ts_decorate12(decorators, target, key, desc) {
34347
+ function _ts_decorate11(decorators, target, key, desc) {
34390
34348
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
34391
34349
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
34392
34350
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
34393
34351
  return c > 3 && r && Object.defineProperty(target, key, r), r;
34394
34352
  }
34395
- __name(_ts_decorate12, "_ts_decorate");
34353
+ __name(_ts_decorate11, "_ts_decorate");
34396
34354
  var StaticModule = class {
34397
34355
  static {
34398
34356
  __name(this, "StaticModule");
34399
34357
  }
34400
34358
  };
34401
- StaticModule = _ts_decorate12([
34359
+ StaticModule = _ts_decorate11([
34402
34360
  Module({
34403
34361
  controllers: [
34404
34362
  StaticController
@@ -34407,13 +34365,13 @@ StaticModule = _ts_decorate12([
34407
34365
  ], StaticModule);
34408
34366
 
34409
34367
  // src/modules/platform/module.ts
34410
- function _ts_decorate13(decorators, target, key, desc) {
34368
+ function _ts_decorate12(decorators, target, key, desc) {
34411
34369
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
34412
34370
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
34413
34371
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
34414
34372
  return c > 3 && r && Object.defineProperty(target, key, r), r;
34415
34373
  }
34416
- __name(_ts_decorate13, "_ts_decorate");
34374
+ __name(_ts_decorate12, "_ts_decorate");
34417
34375
  var PLATFORM_MODULE_OPTIONS = /* @__PURE__ */ Symbol("PLATFORM_MODULE_OPTIONS");
34418
34376
  var PlatformModule = class _PlatformModule {
34419
34377
  static {
@@ -34553,7 +34511,6 @@ var PlatformModule = class _PlatformModule {
34553
34511
  consumer.apply(UserContextMiddleware, RequestContextMiddleware, LoggerContextMiddleware, ObservableTraceMiddleware, ...DISABLE_DATAPASS ? [] : [
34554
34512
  SqlExecutionContextMiddleware
34555
34513
  ]).forRoutes("/*");
34556
- consumer.apply(LegacyPathRedirectMiddleware).forRoutes("/*");
34557
34514
  consumer.apply(CsrfTokenMiddleware, ViewContextMiddleware).exclude("/api/(.*)", "/static/(.*)").forRoutes("*");
34558
34515
  if (options.enableCsrf !== false) {
34559
34516
  const csrfRoutes = options.csrfRoutes || "/api/*";
@@ -34567,7 +34524,7 @@ var PlatformModule = class _PlatformModule {
34567
34524
  }
34568
34525
  }
34569
34526
  };
34570
- PlatformModule = _ts_decorate13([
34527
+ PlatformModule = _ts_decorate12([
34571
34528
  Global(),
34572
34529
  Module2({})
34573
34530
  ], PlatformModule);
@@ -34577,6 +34534,43 @@ var import_express = __toESM(require_express2(), 1);
34577
34534
  import { AppLogger as AppLogger3 } from "@lark-apaas/nestjs-logger";
34578
34535
  import cookieParser from "cookie-parser";
34579
34536
  import { DevToolsV2Module } from "@lark-apaas/nestjs-openapi-devtools";
34537
+
34538
+ // src/middlewares/legacy-path-redirect/index.ts
34539
+ var LEGACY_ROUTE_PATTERNS = [
34540
+ /^\/af\/p\/([^/]+)(\/.*)?$/,
34541
+ /^\/spark\/faas\/([^/]+)(\/.*)?$/
34542
+ ];
34543
+ function createLegacyPathRedirectMiddleware() {
34544
+ return (req, res, next) => {
34545
+ const basePath = process.env.CLIENT_BASE_PATH ?? "";
34546
+ if (!/^\/app\/[^/]/.test(basePath)) {
34547
+ return next();
34548
+ }
34549
+ for (const pattern of LEGACY_ROUTE_PATTERNS) {
34550
+ const match = req.path.match(pattern);
34551
+ if (match) {
34552
+ const appId = match[1];
34553
+ const suffix = match[2] || "/";
34554
+ const querySuffix = req.originalUrl.slice(req.path.length);
34555
+ const normalized = basePath.replace(/\/+$/, "");
34556
+ const basePrefix = normalized.slice(0, normalized.lastIndexOf("/"));
34557
+ const newUrl = `${basePrefix}/${appId}${suffix}${querySuffix}`;
34558
+ if (suffix.startsWith("/api/") || suffix.startsWith("/__innerapi__/")) {
34559
+ req.url = newUrl;
34560
+ return next();
34561
+ }
34562
+ if (req.method === "GET") {
34563
+ return res.redirect(302, newUrl);
34564
+ }
34565
+ return next();
34566
+ }
34567
+ }
34568
+ return next();
34569
+ };
34570
+ }
34571
+ __name(createLegacyPathRedirectMiddleware, "createLegacyPathRedirectMiddleware");
34572
+
34573
+ // src/setup.ts
34580
34574
  var DEFAULT_BODY_LIMIT = "1mb";
34581
34575
  var defaultPerms = {
34582
34576
  disableSwagger: false
@@ -34593,6 +34587,7 @@ async function configureApp(app, perms = defaultPerms) {
34593
34587
  extended: true
34594
34588
  }));
34595
34589
  app.use(cookieParser());
34590
+ app.use(createLegacyPathRedirectMiddleware());
34596
34591
  const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
34597
34592
  app.setGlobalPrefix(globalPrefix);
34598
34593
  app.set("trust proxy", true);
@@ -34629,13 +34624,13 @@ export {
34629
34624
  DevToolsModule,
34630
34625
  DevToolsV2Module2 as DevToolsV2Module,
34631
34626
  FileService,
34632
- LegacyPathRedirectMiddleware,
34633
34627
  PlatformHttpClientService,
34634
34628
  PlatformModule,
34635
34629
  StaticModule,
34636
34630
  UserContextMiddleware,
34637
34631
  ViewContextMiddleware,
34638
- configureApp
34632
+ configureApp,
34633
+ createLegacyPathRedirectMiddleware
34639
34634
  };
34640
34635
  /*! Bundled license information:
34641
34636
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-nestjs-core",
3
- "version": "1.1.24-alpha.26",
3
+ "version": "1.1.24-alpha.28",
4
4
  "description": "FullStack Nestjs Core",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",