@innet/server 1.4.3 → 1.4.4

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/README.md CHANGED
@@ -213,14 +213,14 @@ You can return a file as a response.
213
213
  ```typescript jsx
214
214
  export default (
215
215
  <server>
216
- <header name='content-type' value='text/html'>
216
+ <header name='cache-control' value='max-age=300'>
217
217
  <file path='index.html' />
218
218
  </header>
219
219
  </server>
220
220
  )
221
221
  ```
222
222
 
223
- In this case `content-type` will be equal to `text/html` even if the file does not exist.
223
+ In this case `cache-control` will be equal to `max-age=300` even if the file does not exist.
224
224
 
225
225
  You can put content into the file to apply it only if the file does exist.
226
226
 
@@ -228,7 +228,7 @@ You can put content into the file to apply it only if the file does exist.
228
228
  export default (
229
229
  <server>
230
230
  <file path='index.html'>
231
- <header name='content-type' value='text/html' />
231
+ <header name='cache-control' value='max-age=300' />
232
232
  </file>
233
233
  </server>
234
234
  )
@@ -394,7 +394,7 @@ export default (
394
394
 
395
395
  It will check if the file exist in cms folder then returns the file else returns `404.html`.
396
396
 
397
- You can add prefix with router to handle specific path.
397
+ You can use prefix with router to handle specific path.
398
398
 
399
399
  ```typescript jsx
400
400
  export default (
@@ -409,6 +409,21 @@ export default (
409
409
  )
410
410
  ```
411
411
 
412
+ You can input something into `cms`, if requested file is exist then the content should be used.
413
+
414
+ ```typescript jsx
415
+ export default (
416
+ <server>
417
+ <switch>
418
+ <cms dir='cms'>
419
+ <header name='cache-control' value='max-age=300' />
420
+ </cms>
421
+ <file path='404.html' />
422
+ </switch>
423
+ </server>
424
+ )
425
+ ```
426
+
412
427
  ## proxy
413
428
  You can proxy request.
414
429
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@innet/server",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "description": "Create server-side application with innet",
5
5
  "main": "index.js",
6
6
  "module": "index.es6.js",
@@ -4,5 +4,6 @@ export interface CmsProps {
4
4
  }
5
5
  export interface CmsJsxElement {
6
6
  props: CmsProps;
7
+ children?: any;
7
8
  }
8
- export declare function cms({ props }: CmsJsxElement, handler: any): Promise<unknown>;
9
+ export declare function cms({ props, children }: CmsJsxElement, handler: any): Promise<unknown>;
@@ -2,7 +2,7 @@ import path from 'path';
2
2
  import { file } from '../file/file.es6.js';
3
3
  import { ACTION } from '../../action/Action/Action.es6.js';
4
4
 
5
- function cms({ props }, handler) {
5
+ function cms({ props, children }, handler) {
6
6
  const action = handler[ACTION];
7
7
  const { req } = action;
8
8
  if (!req) {
@@ -19,7 +19,7 @@ function cms({ props }, handler) {
19
19
  }
20
20
  }
21
21
  const filePath = path.join(dir, url);
22
- return file({ props: { path: filePath } }, handler);
22
+ return file({ props: { path: filePath }, children }, handler);
23
23
  }
24
24
 
25
25
  export { cms };
@@ -11,7 +11,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
11
11
  var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
12
12
 
13
13
  function cms(_a, handler) {
14
- var props = _a.props;
14
+ var props = _a.props, children = _a.children;
15
15
  var action = handler[Action.ACTION];
16
16
  var req = action.req;
17
17
  if (!req) {
@@ -28,7 +28,7 @@ function cms(_a, handler) {
28
28
  }
29
29
  }
30
30
  var filePath = path__default["default"].join(dir, url);
31
- return file.file({ props: { path: filePath } }, handler);
31
+ return file.file({ props: { path: filePath }, children: children }, handler);
32
32
  }
33
33
 
34
34
  exports.cms = cms;
@@ -1,3 +1,4 @@
1
+ import innet from 'innet';
1
2
  import fs from 'fs';
2
3
  import mime from 'mime';
3
4
  import { ACTION } from '../../action/Action/Action.es6.js';
@@ -8,14 +9,23 @@ function file({ props, children = null }, handler) {
8
9
  if (fs.existsSync(path)) {
9
10
  const stat = fs.statSync(path);
10
11
  if (stat.isFile()) {
11
- res.writeHead(200, {
12
- 'Content-Type': mime.getType(path),
13
- 'Content-Length': stat.size,
14
- });
15
12
  const readStream = fs.createReadStream(path);
16
- readStream.pipe(res);
13
+ const result = innet(children, handler);
14
+ const run = () => {
15
+ res.writeHead(200, {
16
+ 'Content-Type': mime.getType(path),
17
+ 'Content-Length': stat.size,
18
+ });
19
+ readStream.pipe(res);
20
+ };
21
+ if (result instanceof Promise) {
22
+ result.then(run);
23
+ }
24
+ else {
25
+ run();
26
+ }
17
27
  return new Promise((resolve, reject) => {
18
- readStream.once('end', () => resolve(children));
28
+ readStream.once('end', () => resolve(result));
19
29
  readStream.once('error', reject);
20
30
  });
21
31
  }
@@ -2,12 +2,14 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var innet = require('innet');
5
6
  var fs = require('fs');
6
7
  var mime = require('mime');
7
8
  var Action = require('../../action/Action/Action.js');
8
9
 
9
10
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
11
 
12
+ var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
11
13
  var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
12
14
  var mime__default = /*#__PURE__*/_interopDefaultLegacy(mime);
13
15
 
@@ -16,16 +18,25 @@ function file(_a, handler) {
16
18
  var res = handler[Action.ACTION].res;
17
19
  var path = props.path;
18
20
  if (fs__default["default"].existsSync(path)) {
19
- var stat = fs__default["default"].statSync(path);
20
- if (stat.isFile()) {
21
- res.writeHead(200, {
22
- 'Content-Type': mime__default["default"].getType(path),
23
- 'Content-Length': stat.size,
24
- });
21
+ var stat_1 = fs__default["default"].statSync(path);
22
+ if (stat_1.isFile()) {
25
23
  var readStream_1 = fs__default["default"].createReadStream(path);
26
- readStream_1.pipe(res);
24
+ var result_1 = innet__default["default"](children, handler);
25
+ var run = function () {
26
+ res.writeHead(200, {
27
+ 'Content-Type': mime__default["default"].getType(path),
28
+ 'Content-Length': stat_1.size,
29
+ });
30
+ readStream_1.pipe(res);
31
+ };
32
+ if (result_1 instanceof Promise) {
33
+ result_1.then(run);
34
+ }
35
+ else {
36
+ run();
37
+ }
27
38
  return new Promise(function (resolve, reject) {
28
- readStream_1.once('end', function () { return resolve(children); });
39
+ readStream_1.once('end', function () { return resolve(result_1); });
29
40
  readStream_1.once('error', reject);
30
41
  });
31
42
  }