express-ext 0.4.0 → 0.4.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/resources.js CHANGED
@@ -1,95 +1,97 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- var fs = require('fs');
4
- var http = require('http');
5
- var https = require('https');
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", { value: true })
3
+ var fs = require("fs")
4
+ var http = require("http")
5
+ var https = require("https")
6
6
  var resources = (function () {
7
7
  function resources() {}
8
- resources.limits = [12, 24, 60, 100, 120, 180, 300, 600];
9
- resources.pages = 'pages';
10
- resources.page = 'page';
11
- resources.limit = 'limit';
12
- resources.defaultLimit = 12;
13
- resources.sort = 'sort';
14
- resources.partial = 'partial';
15
- resources.encoding = 'utf-8';
16
- return resources;
17
- })();
18
- exports.resources = resources;
8
+ resources.limits = [12, 24, 60, 100, 120, 180, 300, 600]
9
+ resources.pages = "pages"
10
+ resources.page = "page"
11
+ resources.nextPageToken = "next"
12
+ resources.limit = "limit"
13
+ resources.defaultLimit = 12
14
+ resources.sort = "sort"
15
+ resources.fields = "fields"
16
+ resources.partial = "partial"
17
+ resources.encoding = "utf-8"
18
+ return resources
19
+ })()
20
+ exports.resources = resources
19
21
  function getView(req, view) {
20
- var partial = req.query[resources.partial];
21
- return partial == 'true' ? resources.pages + '/' + view : view;
22
+ var partial = req.query[resources.partial]
23
+ return partial == "true" ? resources.pages + "/" + view : view
22
24
  }
23
- exports.getView = getView;
25
+ exports.getView = getView
24
26
  var TypeChecker = (function () {
25
27
  function TypeChecker(attributes, allowUndefined) {
26
- this.attributes = attributes;
27
- this.allowUndefined = allowUndefined;
28
- this.check = this.check.bind(this);
28
+ this.attributes = attributes
29
+ this.allowUndefined = allowUndefined
30
+ this.check = this.check.bind(this)
29
31
  }
30
32
  TypeChecker.prototype.check = function (req, res, next) {
31
- var obj = req.body;
32
- if (!obj || obj === '') {
33
- res.status(400).end('The request body cannot be empty');
33
+ var obj = req.body
34
+ if (!obj || obj === "") {
35
+ res.status(400).end("The request body cannot be empty")
34
36
  } else {
35
- var errors = resources.check(obj, this.attributes, this.allowUndefined);
37
+ var errors = resources.check(obj, this.attributes, this.allowUndefined)
36
38
  if (errors.length > 0) {
37
- res.status(400).json(errors).end();
39
+ res.status(400).json(errors).end()
38
40
  } else {
39
- next();
41
+ next()
40
42
  }
41
43
  }
42
- };
43
- return TypeChecker;
44
- })();
45
- exports.TypeChecker = TypeChecker;
44
+ }
45
+ return TypeChecker
46
+ })()
47
+ exports.TypeChecker = TypeChecker
46
48
  function check(attributes, allowUndefined) {
47
- var x = new TypeChecker(attributes, allowUndefined);
48
- return x.check;
49
+ var x = new TypeChecker(attributes, allowUndefined)
50
+ return x.check
49
51
  }
50
- exports.check = check;
52
+ exports.check = check
51
53
  function loadTemplates(ok, buildTemplates, correct, files) {
52
54
  if (!ok) {
53
- return undefined;
55
+ return undefined
54
56
  }
55
57
  if (!files) {
56
- files = ['./src/query.xml'];
58
+ files = ["./src/query.xml"]
57
59
  }
58
- var mappers = [];
60
+ var mappers = []
59
61
  for (var _i = 0, files_1 = files; _i < files_1.length; _i++) {
60
- var file = files_1[_i];
61
- var mapper = fs.readFileSync(file, 'utf8');
62
- mappers.push(mapper);
62
+ var file = files_1[_i]
63
+ var mapper = fs.readFileSync(file, "utf8")
64
+ mappers.push(mapper)
63
65
  }
64
- return buildTemplates(mappers, correct);
66
+ return buildTemplates(mappers, correct)
65
67
  }
66
- exports.loadTemplates = loadTemplates;
68
+ exports.loadTemplates = loadTemplates
67
69
  function start(a, s) {
68
- process.on('uncaughtException', function (err) {
69
- console.log(err);
70
- });
70
+ process.on("uncaughtException", function (err) {
71
+ console.log(err)
72
+ })
71
73
  if (s.https) {
72
74
  if (s.options) {
73
75
  https.createServer(s.options, a).listen(s.port, function () {
74
- console.log('Use https and start server at port ' + s.port);
75
- });
76
+ console.log("Use https and start server at port " + s.port)
77
+ })
76
78
  } else if (s.key && s.cert && s.key.length > 0 && s.cert.length > 0) {
77
79
  var options = {
78
80
  key: fs.readFileSync(s.key),
79
81
  cert: fs.readFileSync(s.cert),
80
- };
82
+ }
81
83
  https.createServer(options, a).listen(s.port, function () {
82
- console.log('Use https and start server at port ' + s.port);
83
- });
84
+ console.log("Use https and start server at port " + s.port)
85
+ })
84
86
  } else {
85
87
  http.createServer(a).listen(s.port, function () {
86
- console.log('Start server at port ' + s.port);
87
- });
88
+ console.log("Start server at port " + s.port)
89
+ })
88
90
  }
89
91
  } else {
90
92
  http.createServer(a).listen(s.port, function () {
91
- console.log('Start server at port ' + s.port);
92
- });
93
+ console.log("Start server at port " + s.port)
94
+ })
93
95
  }
94
96
  }
95
- exports.start = start;
97
+ exports.start = start