@webresto/graphql 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. package/.editorconfig +10 -0
  2. package/index.d.ts +3 -0
  3. package/index.js +22 -0
  4. package/index.ts +14 -0
  5. package/lib/afterHook.d.ts +1 -0
  6. package/lib/afterHook.js +24 -0
  7. package/lib/afterHook.ts +26 -0
  8. package/lib/afterHook.ts___graphql-transport-ws +138 -0
  9. package/lib/afterHook.ts___graphql-ws +133 -0
  10. package/lib/defaults.js +12 -0
  11. package/lib/errorWrapper.d.ts +4 -0
  12. package/lib/errorWrapper.js +13 -0
  13. package/lib/errorWrapper.ts +12 -0
  14. package/lib/eventHelper.d.ts +21 -0
  15. package/lib/eventHelper.js +32 -0
  16. package/lib/eventHelper.ts +35 -0
  17. package/lib/graphqlHelper.d.ts +115 -0
  18. package/lib/graphqlHelper.js +596 -0
  19. package/lib/graphqlHelper.ts +692 -0
  20. package/lib/initialize.d.ts +1 -0
  21. package/lib/initialize.js +22 -0
  22. package/lib/initialize.ts +21 -0
  23. package/notes.md +1976 -0
  24. package/package.json +47 -0
  25. package/readme.md +258 -0
  26. package/restApi.http +11 -0
  27. package/src/additionalResolvers.d.ts +19 -0
  28. package/src/additionalResolvers.js +114 -0
  29. package/src/additionalResolvers.ts +111 -0
  30. package/src/graphql.d.ts +7 -0
  31. package/src/graphql.js +144 -0
  32. package/src/graphql.ts +160 -0
  33. package/src/resolvers/cart.d.ts +123 -0
  34. package/src/resolvers/cart.js +176 -0
  35. package/src/resolvers/cart.ts +256 -0
  36. package/src/resolvers/checkout.d.ts +30 -0
  37. package/src/resolvers/checkout.js +226 -0
  38. package/src/resolvers/checkout.ts +242 -0
  39. package/src/resolvers/dishAndModifier.d.ts +2 -0
  40. package/src/resolvers/dishAndModifier.js +35 -0
  41. package/src/resolvers/dishAndModifier.ts +38 -0
  42. package/src/resolvers/maintenance.d.ts +9 -0
  43. package/src/resolvers/maintenance.js +12 -0
  44. package/src/resolvers/maintenance.ts +11 -0
  45. package/src/resolvers/paymentMethod.d.ts +9 -0
  46. package/src/resolvers/paymentMethod.js +22 -0
  47. package/src/resolvers/paymentMethod.ts +20 -0
  48. package/src/resolvers/restrictions.d.ts +9 -0
  49. package/src/resolvers/restrictions.js +24 -0
  50. package/src/resolvers/restrictions.ts +22 -0
  51. package/src/resolvers/streets.d.ts +9 -0
  52. package/src/resolvers/streets.js +16 -0
  53. package/src/resolvers/streets.ts +13 -0
  54. package/src/resolvers/subscriptions.d.ts +33 -0
  55. package/src/resolvers/subscriptions.js +52 -0
  56. package/src/resolvers/subscriptions.ts +63 -0
  57. package/test/.eslintrc +8 -0
  58. package/test/_bootstrap.js +29 -0
  59. package/test/fixtures/v0.12-app/.gitignore +11 -0
  60. package/test/fixtures/v0.12-app/.sailsrc +11 -0
  61. package/test/fixtures/v0.12-app/api/controllers/.gitkeep +0 -0
  62. package/test/fixtures/v0.12-app/api/models/.gitkeep +0 -0
  63. package/test/fixtures/v0.12-app/api/models/TestModel.js +22 -0
  64. package/test/fixtures/v0.12-app/api/responses/badRequest.js +76 -0
  65. package/test/fixtures/v0.12-app/api/responses/created.js +60 -0
  66. package/test/fixtures/v0.12-app/api/responses/forbidden.js +89 -0
  67. package/test/fixtures/v0.12-app/api/responses/notFound.js +94 -0
  68. package/test/fixtures/v0.12-app/api/responses/ok.js +60 -0
  69. package/test/fixtures/v0.12-app/api/responses/serverError.js +89 -0
  70. package/test/fixtures/v0.12-app/api/services/.gitkeep +0 -0
  71. package/test/fixtures/v0.12-app/app.js +73 -0
  72. package/test/fixtures/v0.12-app/config/bootstrap.js +6 -0
  73. package/test/fixtures/v0.12-app/config/connections.js +5 -0
  74. package/test/fixtures/v0.12-app/config/cors.js +78 -0
  75. package/test/fixtures/v0.12-app/config/csrf.js +64 -0
  76. package/test/fixtures/v0.12-app/config/env/development.js +10 -0
  77. package/test/fixtures/v0.12-app/config/env/production.js +16 -0
  78. package/test/fixtures/v0.12-app/config/globals.js +63 -0
  79. package/test/fixtures/v0.12-app/config/hookTimeout.js +8 -0
  80. package/test/fixtures/v0.12-app/config/http.js +93 -0
  81. package/test/fixtures/v0.12-app/config/i18n.js +57 -0
  82. package/test/fixtures/v0.12-app/config/log.js +29 -0
  83. package/test/fixtures/v0.12-app/config/models.js +3 -0
  84. package/test/fixtures/v0.12-app/config/policies.js +51 -0
  85. package/test/fixtures/v0.12-app/config/restoapi.js +3 -0
  86. package/test/fixtures/v0.12-app/config/restocore.js +39 -0
  87. package/test/fixtures/v0.12-app/config/routes.js +49 -0
  88. package/test/fixtures/v0.12-app/config/session.js +100 -0
  89. package/test/fixtures/v0.12-app/config/sockets.js +141 -0
  90. package/test/fixtures/v0.12-app/config/stateflow.js +4 -0
  91. package/test/fixtures/v0.12-app/config/views.js +95 -0
  92. package/test/fixtures/v0.12-app/package.json +34 -0
  93. package/test/fixtures/v0.12-app/views/403.ejs +68 -0
  94. package/test/fixtures/v0.12-app/views/404.ejs +68 -0
  95. package/test/fixtures/v0.12-app/views/500.ejs +73 -0
  96. package/test/fixtures/v0.12-app/views/homepage.ejs +74 -0
  97. package/test/fixtures/v0.12-app/views/layout.ejs +91 -0
  98. package/test/mocha.opts +2 -0
  99. package/test/readme.md +0 -0
  100. package/test/todo +0 -0
  101. package/test/tslint.json +18 -0
  102. package/test/unit/first.test.js +11 -0
  103. package/test/unit/sails_not_crash.test.js +3 -0
  104. package/todo.md +1 -0
  105. package/tsconfig.json +10 -0
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("mocha");
4
+ var Sails = require('./fixtures/v0.12-app/node_modules/sails').Sails;
5
+ before(function (done) {
6
+ let rc = require('./fixtures/v0.12-app/app').rc;
7
+ this.timeout(50000);
8
+ Sails().lift(rc, function (err, _sails) {
9
+ if (err)
10
+ return done(err);
11
+ global.sails = _sails;
12
+ // console.log(_sails);
13
+ return done();
14
+ });
15
+ });
16
+ after(function (done) {
17
+ if (global.sails) {
18
+ return global.sails.lower(function (err) {
19
+ if (err) {
20
+ done();
21
+ return process.exit(2);
22
+ }
23
+ done();
24
+ return process.exit(0);
25
+ });
26
+ }
27
+ done();
28
+ return process.exit(2);
29
+ });
@@ -0,0 +1,11 @@
1
+ *
2
+ !api
3
+ !/api/**/*
4
+ !config
5
+ !/config/**/*
6
+ !views
7
+ !/views/**/*
8
+ !.sailsrc
9
+ !app.js
10
+ !package.json
11
+ !.gitignore
@@ -0,0 +1,11 @@
1
+ {
2
+ "generators": {
3
+ "modules": {}
4
+ },
5
+ "hooks": {
6
+ "grunt": false,
7
+ "sockets": false,
8
+ "pubsub": false,
9
+ "i18n": false
10
+ }
11
+ }
File without changes
@@ -0,0 +1,22 @@
1
+
2
+ module.exports = {
3
+ attributes: {
4
+
5
+ order_number : { type: 'string' },
6
+
7
+ order_id : { type: 'string' },
8
+
9
+ order_id: { type: 'string' },
10
+
11
+ phone : { type: 'string' },
12
+
13
+ notifyMethod : {
14
+ type: 'string'
15
+ },
16
+
17
+ delivered : {
18
+ type: 'json',
19
+ defaultsTo: {new: false}
20
+ },
21
+ },
22
+ }
@@ -0,0 +1,76 @@
1
+ /**
2
+ * 400 (Bad Request) Handler
3
+ *
4
+ * Usage:
5
+ * return res.badRequest();
6
+ * return res.badRequest(data);
7
+ * return res.badRequest(data, 'some/specific/badRequest/view');
8
+ *
9
+ * e.g.:
10
+ * ```
11
+ * return res.badRequest(
12
+ * 'Please choose a valid `password` (6-12 characters)',
13
+ * 'trial/signup'
14
+ * );
15
+ * ```
16
+ */
17
+
18
+ module.exports = function badRequest(data, options) {
19
+
20
+ // Get access to `req`, `res`, & `sails`
21
+ var req = this.req;
22
+ var res = this.res;
23
+ var sails = req._sails;
24
+
25
+ // Set status code
26
+ res.status(400);
27
+
28
+ // Log error to console
29
+ if (data !== undefined) {
30
+ sails.log.verbose('Sending 400 ("Bad Request") response: \n',data);
31
+ }
32
+ else sails.log.verbose('Sending 400 ("Bad Request") response');
33
+
34
+ // Only include errors in response if application environment
35
+ // is not set to 'production'. In production, we shouldn't
36
+ // send back any identifying information about errors.
37
+ if (sails.config.environment === 'production' && sails.config.keepResponseErrors !== true) {
38
+ data = undefined;
39
+ }
40
+
41
+ // If the user-agent wants JSON, always respond with JSON
42
+ // If views are disabled, revert to json
43
+ if (req.wantsJSON || sails.config.hooks.views === false) {
44
+ return res.jsonx(data);
45
+ }
46
+
47
+ // If second argument is a string, we take that to mean it refers to a view.
48
+ // If it was omitted, use an empty object (`{}`)
49
+ options = (typeof options === 'string') ? { view: options } : options || {};
50
+
51
+ // Attempt to prettify data for views, if it's a non-error object
52
+ var viewData = data;
53
+ if (!(viewData instanceof Error) && 'object' == typeof viewData) {
54
+ try {
55
+ viewData = require('util').inspect(data, {depth: null});
56
+ }
57
+ catch(e) {
58
+ viewData = undefined;
59
+ }
60
+ }
61
+
62
+ // If a view was provided in options, serve it.
63
+ // Otherwise try to guess an appropriate view, or if that doesn't
64
+ // work, just send JSON.
65
+ if (options.view) {
66
+ return res.view(options.view, { data: viewData, title: 'Bad Request' });
67
+ }
68
+
69
+ // If no second argument provided, try to serve the implied view,
70
+ // but fall back to sending JSON(P) if no view can be inferred.
71
+ else return res.guessView({ data: viewData, title: 'Bad Request' }, function couldNotGuessView () {
72
+ return res.jsonx(data);
73
+ });
74
+
75
+ };
76
+
@@ -0,0 +1,60 @@
1
+ /**
2
+ * 201 (CREATED) Response
3
+ *
4
+ * Usage:
5
+ * return res.created();
6
+ * return res.created(data);
7
+ * return res.created(data, 'auth/login');
8
+ *
9
+ * @param {Object} data
10
+ * @param {String|Object} options
11
+ * - pass string to render specified view
12
+ */
13
+
14
+ module.exports = function created (data, options) {
15
+
16
+ // Get access to `req`, `res`, & `sails`
17
+ var req = this.req;
18
+ var res = this.res;
19
+ var sails = req._sails;
20
+
21
+ sails.log.silly('res.created() :: Sending 201 ("CREATED") response');
22
+
23
+ // Set status code
24
+ res.status(201);
25
+
26
+ // If appropriate, serve data as JSON(P)
27
+ // If views are disabled, revert to json
28
+ if (req.wantsJSON || sails.config.hooks.views === false) {
29
+ return res.jsonx(data);
30
+ }
31
+
32
+ // If second argument is a string, we take that to mean it refers to a view.
33
+ // If it was omitted, use an empty object (`{}`)
34
+ options = (typeof options === 'string') ? { view: options } : options || {};
35
+
36
+ // Attempt to prettify data for views, if it's a non-error object
37
+ var viewData = data;
38
+ if (!(viewData instanceof Error) && 'object' == typeof viewData) {
39
+ try {
40
+ viewData = require('util').inspect(data, {depth: null});
41
+ }
42
+ catch(e) {
43
+ viewData = undefined;
44
+ }
45
+ }
46
+
47
+ // If a view was provided in options, serve it.
48
+ // Otherwise try to guess an appropriate view, or if that doesn't
49
+ // work, just send JSON.
50
+ if (options.view) {
51
+ return res.view(options.view, { data: viewData, title: 'Created' });
52
+ }
53
+
54
+ // If no second argument provided, try to serve the implied view,
55
+ // but fall back to sending JSON(P) if no view can be inferred.
56
+ else return res.guessView({ data: viewData, title: 'Created' }, function couldNotGuessView () {
57
+ return res.jsonx(data);
58
+ });
59
+
60
+ };
@@ -0,0 +1,89 @@
1
+ /**
2
+ * 403 (Forbidden) Handler
3
+ *
4
+ * Usage:
5
+ * return res.forbidden();
6
+ * return res.forbidden(err);
7
+ * return res.forbidden(err, 'some/specific/forbidden/view');
8
+ *
9
+ * e.g.:
10
+ * ```
11
+ * return res.forbidden('Access denied.');
12
+ * ```
13
+ */
14
+
15
+ module.exports = function forbidden (data, options) {
16
+
17
+ // Get access to `req`, `res`, & `sails`
18
+ var req = this.req;
19
+ var res = this.res;
20
+ var sails = req._sails;
21
+
22
+ // Set status code
23
+ res.status(403);
24
+
25
+ // Log error to console
26
+ if (data !== undefined) {
27
+ sails.log.verbose('Sending 403 ("Forbidden") response: \n',data);
28
+ }
29
+ else sails.log.verbose('Sending 403 ("Forbidden") response');
30
+
31
+ // Only include errors in response if application environment
32
+ // is not set to 'production'. In production, we shouldn't
33
+ // send back any identifying information about errors.
34
+ if (sails.config.environment === 'production' && sails.config.keepResponseErrors !== true) {
35
+ data = undefined;
36
+ }
37
+
38
+ // If the user-agent wants JSON, always respond with JSON
39
+ // If views are disabled, revert to json
40
+ if (req.wantsJSON || sails.config.hooks.views === false) {
41
+ return res.jsonx(data);
42
+ }
43
+
44
+ // If second argument is a string, we take that to mean it refers to a view.
45
+ // If it was omitted, use an empty object (`{}`)
46
+ options = (typeof options === 'string') ? { view: options } : options || {};
47
+
48
+ // Attempt to prettify data for views, if it's a non-error object
49
+ var viewData = data;
50
+ if (!(viewData instanceof Error) && 'object' == typeof viewData) {
51
+ try {
52
+ viewData = require('util').inspect(data, {depth: null});
53
+ }
54
+ catch(e) {
55
+ viewData = undefined;
56
+ }
57
+ }
58
+
59
+ // If a view was provided in options, serve it.
60
+ // Otherwise try to guess an appropriate view, or if that doesn't
61
+ // work, just send JSON.
62
+ if (options.view) {
63
+ return res.view(options.view, { data: viewData, title: 'Forbidden' });
64
+ }
65
+
66
+ // If no second argument provided, try to serve the default view,
67
+ // but fall back to sending JSON(P) if any errors occur.
68
+ else return res.view('403', { data: viewData, title: 'Forbidden' }, function (err, html) {
69
+
70
+ // If a view error occured, fall back to JSON(P).
71
+ if (err) {
72
+ //
73
+ // Additionally:
74
+ // • If the view was missing, ignore the error but provide a verbose log.
75
+ if (err.code === 'E_VIEW_FAILED') {
76
+ sails.log.verbose('res.forbidden() :: Could not locate view for error page (sending JSON instead). Details: ',err);
77
+ }
78
+ // Otherwise, if this was a more serious error, log to the console with the details.
79
+ else {
80
+ sails.log.warn('res.forbidden() :: When attempting to render error page view, an error occured (sending JSON instead). Details: ', err);
81
+ }
82
+ return res.jsonx(data);
83
+ }
84
+
85
+ return res.send(html);
86
+ });
87
+
88
+ };
89
+
@@ -0,0 +1,94 @@
1
+ /**
2
+ * 404 (Not Found) Handler
3
+ *
4
+ * Usage:
5
+ * return res.notFound();
6
+ * return res.notFound(err);
7
+ * return res.notFound(err, 'some/specific/notfound/view');
8
+ *
9
+ * e.g.:
10
+ * ```
11
+ * return res.notFound();
12
+ * ```
13
+ *
14
+ * NOTE:
15
+ * If a request doesn't match any explicit routes (i.e. `config/routes.js`)
16
+ * or route blueprints (i.e. "shadow routes", Sails will call `res.notFound()`
17
+ * automatically.
18
+ */
19
+
20
+ module.exports = function notFound (data, options) {
21
+
22
+ // Get access to `req`, `res`, & `sails`
23
+ var req = this.req;
24
+ var res = this.res;
25
+ var sails = req._sails;
26
+
27
+ // Set status code
28
+ res.status(404);
29
+
30
+ // Log error to console
31
+ if (data !== undefined) {
32
+ sails.log.verbose('Sending 404 ("Not Found") response: \n',data);
33
+ }
34
+ else sails.log.verbose('Sending 404 ("Not Found") response');
35
+
36
+ // Only include errors in response if application environment
37
+ // is not set to 'production'. In production, we shouldn't
38
+ // send back any identifying information about errors.
39
+ if (sails.config.environment === 'production' && sails.config.keepResponseErrors !== true) {
40
+ data = undefined;
41
+ }
42
+
43
+ // If the user-agent wants JSON, always respond with JSON
44
+ // If views are disabled, revert to json
45
+ if (req.wantsJSON || sails.config.hooks.views === false) {
46
+ return res.jsonx(data);
47
+ }
48
+
49
+ // If second argument is a string, we take that to mean it refers to a view.
50
+ // If it was omitted, use an empty object (`{}`)
51
+ options = (typeof options === 'string') ? { view: options } : options || {};
52
+
53
+ // Attempt to prettify data for views, if it's a non-error object
54
+ var viewData = data;
55
+ if (!(viewData instanceof Error) && 'object' == typeof viewData) {
56
+ try {
57
+ viewData = require('util').inspect(data, {depth: null});
58
+ }
59
+ catch(e) {
60
+ viewData = undefined;
61
+ }
62
+ }
63
+
64
+ // If a view was provided in options, serve it.
65
+ // Otherwise try to guess an appropriate view, or if that doesn't
66
+ // work, just send JSON.
67
+ if (options.view) {
68
+ return res.view(options.view, { data: viewData, title: 'Not Found' });
69
+ }
70
+
71
+ // If no second argument provided, try to serve the default view,
72
+ // but fall back to sending JSON(P) if any errors occur.
73
+ else return res.view('404', { data: viewData, title: 'Not Found' }, function (err, html) {
74
+
75
+ // If a view error occured, fall back to JSON(P).
76
+ if (err) {
77
+ //
78
+ // Additionally:
79
+ // • If the view was missing, ignore the error but provide a verbose log.
80
+ if (err.code === 'E_VIEW_FAILED') {
81
+ sails.log.verbose('res.notFound() :: Could not locate view for error page (sending JSON instead). Details: ',err);
82
+ }
83
+ // Otherwise, if this was a more serious error, log to the console with the details.
84
+ else {
85
+ sails.log.warn('res.notFound() :: When attempting to render error page view, an error occured (sending JSON instead). Details: ', err);
86
+ }
87
+ return res.jsonx(data);
88
+ }
89
+
90
+ return res.send(html);
91
+ });
92
+
93
+ };
94
+
@@ -0,0 +1,60 @@
1
+ /**
2
+ * 200 (OK) Response
3
+ *
4
+ * Usage:
5
+ * return res.ok();
6
+ * return res.ok(data);
7
+ * return res.ok(data, 'auth/login');
8
+ *
9
+ * @param {Object} data
10
+ * @param {String|Object} options
11
+ * - pass string to render specified view
12
+ */
13
+
14
+ module.exports = function sendOK (data, options) {
15
+
16
+ // Get access to `req`, `res`, & `sails`
17
+ var req = this.req;
18
+ var res = this.res;
19
+ var sails = req._sails;
20
+
21
+ sails.log.silly('res.ok() :: Sending 200 ("OK") response');
22
+
23
+ // Set status code
24
+ res.status(200);
25
+
26
+ // If appropriate, serve data as JSON(P)
27
+ // If views are disabled, revert to json
28
+ if (req.wantsJSON || sails.config.hooks.views === false) {
29
+ return res.jsonx(data);
30
+ }
31
+
32
+ // If second argument is a string, we take that to mean it refers to a view.
33
+ // If it was omitted, use an empty object (`{}`)
34
+ options = (typeof options === 'string') ? { view: options } : options || {};
35
+
36
+ // Attempt to prettify data for views, if it's a non-error object
37
+ var viewData = data;
38
+ if (!(viewData instanceof Error) && 'object' == typeof viewData) {
39
+ try {
40
+ viewData = require('util').inspect(data, {depth: null});
41
+ }
42
+ catch(e) {
43
+ viewData = undefined;
44
+ }
45
+ }
46
+
47
+ // If a view was provided in options, serve it.
48
+ // Otherwise try to guess an appropriate view, or if that doesn't
49
+ // work, just send JSON.
50
+ if (options.view) {
51
+ return res.view(options.view, { data: viewData, title: 'OK' });
52
+ }
53
+
54
+ // If no second argument provided, try to serve the implied view,
55
+ // but fall back to sending JSON(P) if no view can be inferred.
56
+ else return res.guessView({ data: viewData, title: 'OK' }, function couldNotGuessView () {
57
+ return res.jsonx(data);
58
+ });
59
+
60
+ };
@@ -0,0 +1,89 @@
1
+ /**
2
+ * 500 (Server Error) Response
3
+ *
4
+ * Usage:
5
+ * return res.serverError();
6
+ * return res.serverError(err);
7
+ * return res.serverError(err, 'some/specific/error/view');
8
+ *
9
+ * NOTE:
10
+ * If something throws in a policy or controller, or an internal
11
+ * error is encountered, Sails will call `res.serverError()`
12
+ * automatically.
13
+ */
14
+
15
+ module.exports = function serverError (data, options) {
16
+
17
+ // Get access to `req`, `res`, & `sails`
18
+ var req = this.req;
19
+ var res = this.res;
20
+ var sails = req._sails;
21
+
22
+ // Set status code
23
+ res.status(500);
24
+
25
+ // Log error to console
26
+ if (data !== undefined) {
27
+ sails.log.error('Sending 500 ("Server Error") response: \n',data);
28
+ }
29
+ else sails.log.error('Sending empty 500 ("Server Error") response');
30
+
31
+ // Only include errors in response if application environment
32
+ // is not set to 'production'. In production, we shouldn't
33
+ // send back any identifying information about errors.
34
+ if (sails.config.environment === 'production' && sails.config.keepResponseErrors !== true) {
35
+ data = undefined;
36
+ }
37
+
38
+ // If the user-agent wants JSON, always respond with JSON
39
+ // If views are disabled, revert to json
40
+ if (req.wantsJSON || sails.config.hooks.views === false) {
41
+ return res.jsonx(data);
42
+ }
43
+
44
+ // If second argument is a string, we take that to mean it refers to a view.
45
+ // If it was omitted, use an empty object (`{}`)
46
+ options = (typeof options === 'string') ? { view: options } : options || {};
47
+
48
+ // Attempt to prettify data for views, if it's a non-error object
49
+ var viewData = data;
50
+ if (!(viewData instanceof Error) && 'object' == typeof viewData) {
51
+ try {
52
+ viewData = require('util').inspect(data, {depth: null});
53
+ }
54
+ catch(e) {
55
+ viewData = undefined;
56
+ }
57
+ }
58
+
59
+ // If a view was provided in options, serve it.
60
+ // Otherwise try to guess an appropriate view, or if that doesn't
61
+ // work, just send JSON.
62
+ if (options.view) {
63
+ return res.view(options.view, { data: viewData, title: 'Server Error' });
64
+ }
65
+
66
+ // If no second argument provided, try to serve the default view,
67
+ // but fall back to sending JSON(P) if any errors occur.
68
+ else return res.view('500', { data: viewData, title: 'Server Error' }, function (err, html) {
69
+
70
+ // If a view error occured, fall back to JSON(P).
71
+ if (err) {
72
+ //
73
+ // Additionally:
74
+ // • If the view was missing, ignore the error but provide a verbose log.
75
+ if (err.code === 'E_VIEW_FAILED') {
76
+ sails.log.verbose('res.serverError() :: Could not locate view for error page (sending JSON instead). Details: ',err);
77
+ }
78
+ // Otherwise, if this was a more serious error, log to the console with the details.
79
+ else {
80
+ sails.log.warn('res.serverError() :: When attempting to render error page view, an error occured (sending JSON instead). Details: ', err);
81
+ }
82
+ return res.jsonx(data);
83
+ }
84
+
85
+ return res.send(html);
86
+ });
87
+
88
+ };
89
+
File without changes
@@ -0,0 +1,73 @@
1
+ /**
2
+ * app.js
3
+ *
4
+ * Use `app.js` to run your app without `sails lift`.
5
+ * To start the server, run: `node app.js`.
6
+ *
7
+ * This is handy in situations where the sails CLI is not relevant or useful.
8
+ *
9
+ * For example:
10
+ * => `node app.js`
11
+ * => `forever start app.js`
12
+ * => `node debug app.js`
13
+ * => `modulus deploy`
14
+ * => `heroku scale`
15
+ *
16
+ *
17
+ * The same command-line arguments are supported, e.g.:
18
+ * `node app.js --silent --port=80 --prod`
19
+ */
20
+
21
+
22
+ // Ensure we're in the project directory, so cwd-relative paths work as expected
23
+ // no matter where we actually lift from.
24
+ // > Note: This is not required in order to lift, but it is a convenient default.
25
+ process.chdir(__dirname);
26
+
27
+ // Attempt to import `sails`.
28
+ var sails;
29
+ try {
30
+ sails = require('sails');
31
+ } catch (e) {
32
+ console.error('To run an app using `node app.js`, you usually need to have a version of `sails` installed in the same directory as your app.');
33
+ console.error('To do that, run `npm install sails`');
34
+ console.error('');
35
+ console.error('Alternatively, if you have sails installed globally (i.e. you did `npm install -g sails`), you can use `sails lift`.');
36
+ console.error('When you run `sails lift`, your app will still use a local `./node_modules/sails` dependency if it exists,');
37
+ console.error('but if it doesn\'t, the app will run with the global sails instead!');
38
+ return;
39
+ }
40
+
41
+ // --•
42
+ // Try to get `rc` dependency (for loading `.sailsrc` files).
43
+ var rc;
44
+ try {
45
+ rc = require('rc');
46
+ } catch (e0) {
47
+ try {
48
+ rc = require('sails/node_modules/rc');
49
+ } catch (e1) {
50
+ console.error('Could not find dependency: `rc`.');
51
+ console.error('Your `.sailsrc` file(s) will be ignored.');
52
+ console.error('To resolve this, run:');
53
+ console.error('npm install rc --save');
54
+ rc = function () { return {}; };
55
+ }
56
+ }
57
+
58
+
59
+
60
+ // function sails() {
61
+ // return new Promise(function (resolve, reject) {
62
+ // sails.lift(rc('sails'), (err, _sails) => {
63
+ // if (err) { return done(err); }
64
+ // resolve(_sails);
65
+ // });
66
+ // })
67
+ // }
68
+
69
+
70
+ module.exports = {
71
+ sails: sails,
72
+ rc: rc('sails')
73
+ }
@@ -0,0 +1,6 @@
1
+
2
+
3
+ module.exports.bootstrap = async function(cb) {
4
+
5
+ cb();
6
+ };
@@ -0,0 +1,5 @@
1
+ module.exports.connections = {
2
+ memory: {
3
+ adapter: 'sails-memory',
4
+ }
5
+ };