@blocklet/pages-kit-block-studio 0.1.32 → 0.1.34

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.
@@ -114,7 +114,7 @@ import StateData from './data.json';
114
114
  const router = Router();
115
115
 
116
116
  router.use('/api/resources', initResourceRouter);
117
- router.use('/uploads', initUploaderRouter);
117
+ router.use(initUploaderRouter);
118
118
 
119
119
  let tempStates: any[] = [];
120
120
  let allResourcesComponents: any[] = [];
@@ -1,7 +1,22 @@
1
- // @ts-ignore
2
1
  import { initProxyToMediaKitUploadsMiddleware, initStaticResourceMiddleware } from '@blocklet/uploader-server';
2
+ import compression from 'compression';
3
3
  import express, { Router } from 'express';
4
4
  import { PAGES_KIT_DID, PAGES_KIT_RESOURCE_TYPE, MEDIA_KIT_DID, MEDIA_KIT_RESOURCE_TYPE, PAGES_KIT_BLOCK_STUDIO_DID, PAGES_KIT_BLOCK_STUDIO_RESOURCE_TYPE, } from '../constants';
5
+ // compression options
6
+ const compressionOptions = {
7
+ level: 6, // gzip compression level
8
+ threshold: 1024, // only compress responses larger than 1KB
9
+ filter: (req) => {
10
+ var _a;
11
+ const path = req.path || '';
12
+ const extension = (_a = path.split('.').pop()) === null || _a === void 0 ? void 0 : _a.toLowerCase();
13
+ // compressible file types
14
+ const compressibleExtensions = ['json', 'js', 'css', 'html', 'txt', 'svg', 'xml'];
15
+ return extension ? compressibleExtensions.includes(extension) : false;
16
+ },
17
+ // enable brotli support
18
+ brotli: {},
19
+ };
5
20
  // init uploader router
6
21
  export const initUploaderRouter = Router();
7
22
  const staticResourceMiddleware = initStaticResourceMiddleware({
@@ -28,12 +43,12 @@ const staticResourceMiddleware = initStaticResourceMiddleware({
28
43
  },
29
44
  ],
30
45
  });
31
- initUploaderRouter.use('/uploads', initProxyToMediaKitUploadsMiddleware({
46
+ initUploaderRouter.use('/uploads', compression(compressionOptions), initProxyToMediaKitUploadsMiddleware({
32
47
  express,
33
48
  }), staticResourceMiddleware, (_req, res) => {
34
49
  res.status(404).send('404 NOT FOUND').end();
35
50
  });
36
- initUploaderRouter.use('/chunks', staticResourceMiddleware, (_req, res) => {
51
+ initUploaderRouter.use('/chunks', compression(compressionOptions), staticResourceMiddleware, (_req, res) => {
37
52
  res.status(404).send('CHUNK NOT FOUND').end();
38
53
  });
39
54
  export default initUploaderRouter;