@projectinvicta/nails 2.0.15

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.
Files changed (164) hide show
  1. package/README.md +419 -0
  2. package/bin/lib/init.js +103 -0
  3. package/bin/lib/nails.c +81 -0
  4. package/bin/lib/nails.js +23 -0
  5. package/bin/lib/test.js +4 -0
  6. package/index.js +6 -0
  7. package/lib/application.js +24 -0
  8. package/lib/collection.js +6 -0
  9. package/lib/controller.js +182 -0
  10. package/lib/database_connector.js +12 -0
  11. package/lib/firebase_connector.js +94 -0
  12. package/lib/model_v2.js +24 -0
  13. package/lib/mongoose_connector.js +49 -0
  14. package/lib/mongoose_mem_connector.js +21 -0
  15. package/lib/nails.js +244 -0
  16. package/lib/router.js +202 -0
  17. package/lib/sequelize_connector.js +31 -0
  18. package/lib/server.js +1 -0
  19. package/package.json +60 -0
  20. package/scripts/install.js +57 -0
  21. package/scripts/uninstall.js +23 -0
  22. package/spec/bin/init.spec.js +0 -0
  23. package/spec/controller.spec.js +105 -0
  24. package/spec/model_v2.spec.js +75 -0
  25. package/spec/mongodb_connector.util.js +30 -0
  26. package/spec/mongoose_connector.util.js +20 -0
  27. package/spec/nails.spec.js +0 -0
  28. package/spec/router.spec.js +101 -0
  29. package/spec/sequelize_connector.spec.js +91 -0
  30. package/spec/sequelize_connector.util.js +18 -0
  31. package/spec/services/integration/README.md +5 -0
  32. package/spec/services/integration/client/css/styles.css +0 -0
  33. package/spec/services/integration/client/download.jpg +0 -0
  34. package/spec/services/integration/client/favicon.ico +0 -0
  35. package/spec/services/integration/client/index.html +9 -0
  36. package/spec/services/integration/client/js/client.js +0 -0
  37. package/spec/services/integration/client/js/components/app.jsx +15 -0
  38. package/spec/services/integration/config/db.js +14 -0
  39. package/spec/services/integration/config/mimes.js +61 -0
  40. package/spec/services/integration/config/routes.js +41 -0
  41. package/spec/services/integration/config/service.js +48 -0
  42. package/spec/services/integration/config/ssl/certificate.pem +22 -0
  43. package/spec/services/integration/config/ssl/csr.csr +17 -0
  44. package/spec/services/integration/config/ssl/key.pem +28 -0
  45. package/spec/services/integration/config/ssl/private_key.pem +30 -0
  46. package/spec/services/integration/config/ssl/public_key.pem +9 -0
  47. package/spec/services/integration/package.json +23 -0
  48. package/spec/services/integration/server/controllers/classbased_controller.js +33 -0
  49. package/spec/services/integration/server/controllers/default_json_controller.js +20 -0
  50. package/spec/services/integration/server/controllers/error_controller.js +27 -0
  51. package/spec/services/integration/server/controllers/home_controller.js +39 -0
  52. package/spec/services/integration/server/controllers/json_controller.js +15 -0
  53. package/spec/services/integration/server/controllers/manualrenderasync_controller.js +14 -0
  54. package/spec/services/integration/server/controllers/mjs_controller.mjs +13 -0
  55. package/spec/services/integration/server/controllers/modeltest_controller.js +18 -0
  56. package/spec/services/integration/server/controllers/websocket_controller.js +13 -0
  57. package/spec/services/integration/server/models/dog.js +6 -0
  58. package/spec/services/integration/server/views/defaultjson/testnojson.ejs +1 -0
  59. package/spec/services/integration/server/views/testreact/testreact.ejs +15 -0
  60. package/spec/services/integration/server.js +9 -0
  61. package/spec/services/integration_sequelize/README.md +5 -0
  62. package/spec/services/integration_sequelize/client/css/styles.css +0 -0
  63. package/spec/services/integration_sequelize/client/download.jpg +0 -0
  64. package/spec/services/integration_sequelize/client/favicon.ico +0 -0
  65. package/spec/services/integration_sequelize/client/index.html +9 -0
  66. package/spec/services/integration_sequelize/client/js/client.js +0 -0
  67. package/spec/services/integration_sequelize/client/js/components/app.jsx +15 -0
  68. package/spec/services/integration_sequelize/config/db.js +4 -0
  69. package/spec/services/integration_sequelize/config/mimes.js +61 -0
  70. package/spec/services/integration_sequelize/config/routes.js +25 -0
  71. package/spec/services/integration_sequelize/config/service.js +48 -0
  72. package/spec/services/integration_sequelize/config/ssl/certificate.pem +22 -0
  73. package/spec/services/integration_sequelize/config/ssl/csr.csr +17 -0
  74. package/spec/services/integration_sequelize/config/ssl/key.pem +28 -0
  75. package/spec/services/integration_sequelize/config/ssl/private_key.pem +30 -0
  76. package/spec/services/integration_sequelize/config/ssl/public_key.pem +9 -0
  77. package/spec/services/integration_sequelize/package.json +23 -0
  78. package/spec/services/integration_sequelize/server/controllers/default_json_controller.js +21 -0
  79. package/spec/services/integration_sequelize/server/controllers/home_controller.js +39 -0
  80. package/spec/services/integration_sequelize/server/models/dog.js +7 -0
  81. package/spec/services/integration_sequelize/server/models/owner.js +10 -0
  82. package/spec/services/integration_sequelize/server/views/defaultjson/testnojson.ejs +1 -0
  83. package/spec/services/integration_sequelize/server/views/testreact/testreact.ejs +15 -0
  84. package/spec/services/integration_sequelize/server.js +9 -0
  85. package/spec/services.integration.spec.js +296 -0
  86. package/spec/services.integration_sequelize.spec.js +60 -0
  87. package/templates/bin/promote.sh +20 -0
  88. package/templates/bin/rollout.sh +74 -0
  89. package/templates/bin/server.js +6 -0
  90. package/templates/bin/start.sh +16 -0
  91. package/templates/common/readme_fetcher.js +4 -0
  92. package/templates/config/db.js +19 -0
  93. package/templates/config/mimes.js +59 -0
  94. package/templates/config/routes.js +38 -0
  95. package/templates/config/service.js +45 -0
  96. package/templates/config/ssl/certificate.pem +22 -0
  97. package/templates/config/ssl/csr.csr +17 -0
  98. package/templates/config/ssl/key.pem +28 -0
  99. package/templates/config/ssl/private_key.pem +30 -0
  100. package/templates/config/ssl/public_key.pem +9 -0
  101. package/templates/default/bin/promote.sh +20 -0
  102. package/templates/default/bin/rollout.sh +74 -0
  103. package/templates/default/bin/server.js +6 -0
  104. package/templates/default/bin/start.sh +16 -0
  105. package/templates/default/common/readme_fetcher.js +4 -0
  106. package/templates/default/config/db.js +19 -0
  107. package/templates/default/config/mimes.js +59 -0
  108. package/templates/default/config/routes.js +38 -0
  109. package/templates/default/config/service.js +45 -0
  110. package/templates/default/config/ssl/certificate.pem +22 -0
  111. package/templates/default/config/ssl/csr.csr +17 -0
  112. package/templates/default/config/ssl/key.pem +28 -0
  113. package/templates/default/config/ssl/private_key.pem +30 -0
  114. package/templates/default/config/ssl/public_key.pem +9 -0
  115. package/templates/default/package-lock.json +9048 -0
  116. package/templates/default/package.json +43 -0
  117. package/templates/default/public/README.xml +332 -0
  118. package/templates/default/public/css/styles.css +17 -0
  119. package/templates/default/public/download.jpg +0 -0
  120. package/templates/default/public/favicon.ico +0 -0
  121. package/templates/default/public/index.html +9 -0
  122. package/templates/default/public/js/client.js +1 -0
  123. package/templates/default/server/controllers/home_controller.js +34 -0
  124. package/templates/default/server/models/User.js +18 -0
  125. package/templates/default/server/views/home/index.ejs +14 -0
  126. package/templates/default/server/views/partials/javascripts.ejs +1 -0
  127. package/templates/default/server/views/partials/reactapp.ejs +1 -0
  128. package/templates/default/server/views/partials/styles.ejs +3 -0
  129. package/templates/default/spec/User.test.js +20 -0
  130. package/templates/default/spec/home_controller.test.js +28 -0
  131. package/templates/default/spec/setupTests.js +0 -0
  132. package/templates/default/src/AboutPage.jsx +9 -0
  133. package/templates/default/src/HomePage.jsx +9 -0
  134. package/templates/default/src/Layout.jsx +78 -0
  135. package/templates/default/src/ReadmePage.jsx +7 -0
  136. package/templates/default/src/app.jsx +29 -0
  137. package/templates/default/src/components/ReadmeLoader.jsx +13 -0
  138. package/templates/default/src/styles/appstyles.css +3 -0
  139. package/templates/default/vite.config.ts +42 -0
  140. package/templates/package-lock.json +9048 -0
  141. package/templates/package.json +43 -0
  142. package/templates/public/README.xml +332 -0
  143. package/templates/public/css/styles.css +17 -0
  144. package/templates/public/download.jpg +0 -0
  145. package/templates/public/favicon.ico +0 -0
  146. package/templates/public/index.html +9 -0
  147. package/templates/public/js/client.js +1 -0
  148. package/templates/server/controllers/home_controller.js +34 -0
  149. package/templates/server/models/User.js +18 -0
  150. package/templates/server/views/home/index.ejs +14 -0
  151. package/templates/server/views/partials/javascripts.ejs +1 -0
  152. package/templates/server/views/partials/reactapp.ejs +1 -0
  153. package/templates/server/views/partials/styles.ejs +3 -0
  154. package/templates/spec/User.test.js +20 -0
  155. package/templates/spec/home_controller.test.js +28 -0
  156. package/templates/spec/setupTests.js +0 -0
  157. package/templates/src/AboutPage.jsx +9 -0
  158. package/templates/src/HomePage.jsx +9 -0
  159. package/templates/src/Layout.jsx +78 -0
  160. package/templates/src/ReadmePage.jsx +7 -0
  161. package/templates/src/app.jsx +29 -0
  162. package/templates/src/components/ReadmeLoader.jsx +13 -0
  163. package/templates/src/styles/appstyles.css +3 -0
  164. package/templates/vite.config.ts +42 -0
@@ -0,0 +1,101 @@
1
+ // var express_app = require('../lib/application.js');
2
+ import Router from '../lib/router.js';
3
+ import assert from 'assert';
4
+ import express_app from '../lib/application.js';
5
+
6
+ express_app.set("public_root", import.meta.dirname + "/services/integration/public");
7
+ var testRoutes = [
8
+ ['GET', '^/$', {controller: 'testController', action: 'testAction'}],
9
+ ['GET', /^\/public\/*/, {public: true}]
10
+ ];
11
+
12
+ var router;
13
+
14
+ describe('Router', function() {
15
+ describe('route', function() {
16
+ beforeEach(function() {
17
+ router = new Router(testRoutes);
18
+ });
19
+ it(`should emit dispatchTo:application if a registered controller does
20
+ not match the action`,
21
+ function(done) {
22
+ var mockRequest = {
23
+ method: 'get',
24
+ url: 'http://www.test.com/public/test.html'
25
+ };
26
+ var mockResponse = {};
27
+ var expectedAction = '404';
28
+ var testFunctionCalled;
29
+ router.on('dispatchTo:application', test);
30
+
31
+ function test(action, params, request, response) {
32
+ testFunctionCalled = true;
33
+ assert.equal(action, expectedAction);
34
+ assert.equal(typeof(params), 'object');
35
+ assert.equal(params.file, undefined);
36
+ assert.equal(request, mockRequest);
37
+ assert.equal(response, mockResponse);
38
+ done();
39
+ }
40
+ router.route(mockRequest, mockResponse);
41
+ if (!testFunctionCalled) done('testFailed');
42
+ });
43
+ it('should emit dispatch:<controller> event based on the params',
44
+ function(done) {
45
+ const mockParams = {
46
+ _controller: "test",
47
+ _action: "testAction"
48
+ };
49
+ var mockRequest = {
50
+ method: 'get',
51
+ url: 'http://www.test.com/',
52
+ params: mockParams
53
+ };
54
+ var mockResponse = {};
55
+ var expectedAction = 'testAction';
56
+ var testFunctionCalled;
57
+ router.on('dispatchTo:test', test);
58
+
59
+ function test(action, params, request, response) {
60
+ testFunctionCalled = true;
61
+ assert.equal(action, expectedAction);
62
+ assert.equal(params._controller, mockParams._controller);
63
+ assert.equal(params._action, mockParams._action);
64
+ assert.equal(request, mockRequest);
65
+ assert.equal(response, mockResponse);
66
+ done();
67
+ }
68
+ router.route(mockRequest, mockResponse);
69
+ if (!testFunctionCalled) done('testFailed');
70
+ });
71
+ it("should emit dispatch:<controller> event based on the url query",
72
+ function(done) {
73
+ const mockQuery = {
74
+ _controller: "test",
75
+ _action: "testAction"
76
+ };
77
+ var mockRequest = {
78
+ method: 'get',
79
+ url: 'http://www.test.com/',
80
+ query: mockQuery
81
+ };
82
+ var mockResponse = {};
83
+ var expectedAction = 'testAction';
84
+ var testFunctionCalled;
85
+ router.on('dispatchTo:test', test);
86
+
87
+ function test(action, params, request, response) {
88
+ testFunctionCalled = true;
89
+ assert.equal(action, expectedAction);
90
+ assert.equal(params._controller, mockQuery._controller);
91
+ assert.equal(params._action, mockQuery._action);
92
+ assert.equal(request, mockRequest);
93
+ assert.equal(response, mockResponse);
94
+ done();
95
+ }
96
+ router.route(mockRequest, mockResponse);
97
+ if (!testFunctionCalled) done('testFailed');
98
+ }
99
+ );
100
+ });
101
+ });
@@ -0,0 +1,91 @@
1
+ // import SequelizeConnector from '../lib/sequelize_connector.js';
2
+ import assert from 'assert';
3
+ import Model from '../lib/model_v2.js';
4
+ import { DataTypes } from 'sequelize';
5
+ import SequelizeConnectorUtil from './sequelize_connector.util.js';
6
+
7
+ const TEST_SCHEMA = {
8
+ name: DataTypes.STRING,
9
+ favoriteColor: {
10
+ type: DataTypes.STRING,
11
+ defaultValue: 'green',
12
+ },
13
+ age: DataTypes.INTEGER,
14
+ cash: DataTypes.INTEGER,
15
+ }
16
+ let TestSequelizeModel = null;
17
+ let TestSequelizeIndexedModel = null;
18
+
19
+ const TEST_OPTIONS = {
20
+ schema: {
21
+ label: DataTypes.STRING,
22
+ value: DataTypes.STRING,
23
+ },
24
+ options: {
25
+ indexes: [
26
+ {
27
+ unique: true,
28
+ fields: ['label', 'value'],
29
+ },
30
+ ],
31
+ },
32
+ };
33
+
34
+ describe('ModelV2 using SequelizeConnector', function() {
35
+ let util;
36
+ beforeEach(async function() {
37
+ util = new SequelizeConnectorUtil();
38
+ const connector = await util.getTestConnector();
39
+ Model.setConnector(connector);
40
+ TestSequelizeModel =
41
+ class TestSequelizeModel extends new Model("TestSequelizeModel", TEST_SCHEMA) {};
42
+ TestSequelizeIndexedModel =
43
+ class TestSequelizeIndexedModel extends new Model("TestSequelizeIndexedModel", TEST_OPTIONS) {};
44
+ await connector.sequelize.sync({ force: true });
45
+ });
46
+
47
+ it("Should be able to create, save, and retrieve a model", async function() {
48
+ const MODEL_NAME = "First test model created";
49
+ const testModel = TestSequelizeModel.build({name: MODEL_NAME});
50
+ await testModel.save();
51
+ const models = await TestSequelizeModel.findAll();
52
+ assert(models.length == 1, "Should have one model");
53
+ assert(models[0].name == MODEL_NAME, "Name should be consistent");
54
+ assert(models[0] instanceof TestSequelizeModel);
55
+ });
56
+
57
+ it("Should be able to create, save, and retrieve a complex model", async function() {
58
+ const MODEL_LABEL = "First test model LABEL";
59
+ const MODEL_VALUE = "First test model VALUE";
60
+ const testModel = await TestSequelizeIndexedModel.create({label: MODEL_LABEL, value: MODEL_VALUE});
61
+ const models = await TestSequelizeIndexedModel.findAll();
62
+ assert(models.length == 1, "Should have one model");
63
+ assert(models[0].label == MODEL_LABEL, "label should be persisted");
64
+ assert(models[0].value == MODEL_VALUE, "value should be persisted");
65
+ assert(models[0] instanceof TestSequelizeIndexedModel);
66
+ });
67
+
68
+ it("Should be able to respect unique indexes", async function() {
69
+ const MODEL_LABEL_0 = "MODEL_LABEL_0";
70
+ const MODEL_VALUE_0 = "MODEL_VALUE_0";
71
+ const MODEL_LABEL_1 = "MODEL_LABEL_1";
72
+ const MODEL_VALUE_1 = "MODEL_VALUE_1";
73
+ const testModels = await TestSequelizeIndexedModel.bulkCreate(
74
+ [
75
+ {label: MODEL_LABEL_0, value: MODEL_VALUE_0},
76
+ {label: MODEL_LABEL_0, value: MODEL_VALUE_1},
77
+ {label: MODEL_LABEL_1, value: MODEL_VALUE_0},
78
+ {label: MODEL_LABEL_1, value: MODEL_VALUE_1},
79
+ ]
80
+ );
81
+ assert(testModels.length == 4, "Should creaete 4 models");
82
+ let indexWasRespected = true;
83
+ try {
84
+ await TestSequelizeIndexedModel.create({label: MODEL_LABEL_0, value: MODEL_VALUE_0});
85
+ indexWasRespected = false;
86
+ } catch(e) {
87
+ console.log("Error was thrown as expected");
88
+ }
89
+ assert(indexWasRespected, "Should have thrown an error")
90
+ });
91
+ });
@@ -0,0 +1,18 @@
1
+ import SequelizeConnector from '../lib/sequelize_connector.js';
2
+
3
+ class SequelizeConnectorUtil {
4
+ constructor() {
5
+ }
6
+
7
+ async getTestConnector() {
8
+ const dbConnector = new SequelizeConnector();
9
+ this.connection = await dbConnector.connect({address: 'sqlite::memory:'});
10
+ debugger;
11
+ return dbConnector;
12
+ }
13
+ async cleanup() {
14
+ debugger;
15
+ }
16
+ }
17
+
18
+ export default SequelizeConnectorUtil;
@@ -0,0 +1,5 @@
1
+ Integration testing (Sans DB Connector)
2
+ ==============
3
+
4
+ The package.json was copied from the example app. This is for integration
5
+ testing nails.
@@ -0,0 +1,9 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ </head>
5
+ <body>
6
+ <h1>Welcome</h1>
7
+ <div></div>
8
+ </body>
9
+ </html>
File without changes
@@ -0,0 +1,15 @@
1
+ // Use frontend React components to build a single-page webapp
2
+ class App extends React.Component {
3
+ render() {
4
+ return (
5
+ <div>
6
+ Successfully rendered your homepage!
7
+ </div>
8
+ );
9
+ }
10
+ }
11
+
12
+ ReactDOM.render(
13
+ <App />,
14
+ document.getElementById('app')
15
+ );
@@ -0,0 +1,14 @@
1
+ export default {
2
+ // connector: 'sqlite3_connector.js',
3
+ // connector: 'mongoose_connector.js',
4
+ connector: 'mongoose_mem_connector.js',
5
+ // url: 'mongodb://localhost',
6
+ // port: 4444,
7
+
8
+ dbName: 'development',
9
+
10
+ // For the sqlite3 connector. Unless a filename is defined, an in-memory
11
+ // database is used. In-memory databases are not persisted, and will be lost
12
+ // when the server is restarted.
13
+ //filename: ':memory:'
14
+ }
@@ -0,0 +1,61 @@
1
+ /**
2
+ * This file uses file extensions in the request to determine
3
+ * the type of an asset and, therefore, where it can be found
4
+ * in the file system.
5
+ *
6
+ * Currently, the supported types are: 'js', 'css', 'html',
7
+ * 'img'
8
+ * TODO: Add supported types pdf ( or document ), and video
9
+ * TODO: move this file into nails. Too annoying for the dev
10
+ * to see and they shouldn't need to have to change it
11
+ */
12
+ /*
13
+ var mimes = {
14
+ // <ext>: '<type>'
15
+ js: 'js',
16
+ jpg: 'image',
17
+ css: 'css',
18
+ html: 'html'
19
+ };
20
+ */
21
+
22
+ var mimes = {
23
+ html: {
24
+ type: 'page',
25
+ contentType: 'text/html'
26
+ },
27
+ js: {
28
+ type: 'script', // the type of the script,
29
+ contentType: 'application/javascript' // Header info
30
+ },
31
+ css: {
32
+ type: 'style',
33
+ contentType: 'text/css'
34
+ },
35
+ ico: {
36
+ type: 'image',
37
+ contentType: 'image/x-icon'
38
+ },
39
+ jpg: {
40
+ type: 'image',
41
+ contentType: 'image/jpeg'
42
+ },
43
+ png: {
44
+ type: 'image',
45
+ contentType: 'image/png'
46
+ },
47
+ pdf: {
48
+ type: 'document',
49
+ contentType: 'application/pdf'
50
+ },
51
+ xml: {
52
+ type: 'data',
53
+ contentType: 'text/xml'
54
+ },
55
+ json: {
56
+ type: 'data',
57
+ contentType: 'application/json'
58
+ }
59
+ }
60
+
61
+ export default mimes;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Routes specifies the array of route definitions to be passed to the router
3
+ *
4
+ * Routes are checked in series, and the first matching route is applied.
5
+ * A route definition is as follows:
6
+ * ['METHOD', 'MATCHER', 'OPTIONS']
7
+ *
8
+ * METHOD => crud methods (GET, PUT, POST, DELETE)
9
+ * MATCHER => to be matched against the path. Captured elements will be passed to options. Delegates to express application routing.
10
+ * OPTIONS => an object with parametes deciding how the route will be handled in order of execution:
11
+ * path: => the path to a static file ( index.html f/e)
12
+ * controller: => controller to route the request to. TODO: May implement a resource definition for automatically routing cruds
13
+ * action: => the method to run in the controller. If not specified, the index method will be called.
14
+ * [1..n]: => each numerical definition defines a parameter in which to store the value of the captured elements in the regex.
15
+ * controller, and action are protected names and will apply the cature to controller name and method respectively.
16
+ * f/e: ['get', /\/(home)/, {0: 'controller'}] => routes to home controller
17
+ * ['get, '/\/home\/(5)/, {controller: 'home', 0: 'id'}] => routes to home controller and adds {id: 5} to the params hash.
18
+ */
19
+
20
+ var routes = [
21
+ // Routes the root request to index.html, as well as all other requests to static
22
+ ['get', "/", {controller: 'home'}],
23
+ // Test controllers defined using ES6 class
24
+ ['get', "/classbased", {controller: 'classbased'}],
25
+ // Test implicit JSON responses
26
+ ['get', "/json/:action", {controller: 'json', json: true}],
27
+ // Test Model creation and retrieval using MongooseConnector
28
+ ['get', "/modeltest/:action", {controller: 'modeltest', json: true}],
29
+ // Routes all requests starting with /public as static requests to the public folder.
30
+ ['get', '/public', {public: true}],
31
+ // A test route which routes the first part of pathname to controller and the second to the action
32
+ ['get', /^\/(\w+)\/(\w+)$/i, {0: 'controller', 1: 'action'}],
33
+ // Maps the first two parts of the path to controller and action, and the third to the id parameter
34
+ ['get', "/:controller/:action/:id"],
35
+ ['get', "/error/fivehundred", {json: true}],
36
+
37
+ ['ws', "/", {controller: 'websocket'}],
38
+ ['ws', "/voodoo", {controller: 'websocket', action: 'voodoo'}]
39
+ ];
40
+
41
+ export default routes;
@@ -0,0 +1,48 @@
1
+ // Initializes application before server starts
2
+ // Each of these is REQUIRED
3
+
4
+ import routes from './routes.js';
5
+ import mimes from './mimes.js';
6
+ import db from './db.js';
7
+
8
+ var SERVER_ROOT = import.meta.dirname + '/..';
9
+ var APP_ROOT = SERVER_ROOT + '/server';
10
+
11
+ // Only for reading the certificates for SSL
12
+ import fs from 'node:fs';
13
+ // const fs = require('fs');
14
+ const PRIVATE_KEY_FILE = fs.readFileSync(`${import.meta.dirname}/ssl/key.pem`);
15
+ const CERTIFICATE_FILE = fs.readFileSync(`${import.meta.dirname}/ssl/certificate.pem`);
16
+
17
+ var config = {
18
+ APP_ROOT: APP_ROOT,
19
+ // root directory for delivering static assets
20
+ PUBLIC_ROOT: SERVER_ROOT + '/client',
21
+ CONTROLLERS_ROOT: APP_ROOT + '/controllers',
22
+ VIEWS_ROOT: APP_ROOT + '/views',
23
+ //MODELS_ROOT: APP_ROOT + '/models',
24
+ SERVER_ROOT: SERVER_ROOT,
25
+
26
+ ENABLE_HTTP: true,
27
+ //IP: "0.0.0.0",
28
+ PORT: 3333,
29
+
30
+ ASYNC: false,
31
+
32
+ // For HTTPS
33
+ ENABLE_HTTPS: true,
34
+ SSL_PORT: 3334,
35
+ PRIVATE_KEY: PRIVATE_KEY_FILE,
36
+ CERTIFICATE: CERTIFICATE_FILE,
37
+ };
38
+
39
+ // module.exports.routes = require('./routes.js');
40
+ // module.exports.mimes = require('./mimes.js');
41
+ // module.exports.db = require('./db.js');
42
+
43
+ export default {
44
+ config,
45
+ routes,
46
+ db,
47
+ mimes,
48
+ }
@@ -0,0 +1,22 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDrzCCApegAwIBAgIUR04h3qlfhW5SYQrnm0VjDSLQrwUwDQYJKoZIhvcNAQEL
3
+ BQAwZzELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMQ4wDAYDVQQKDAVOYWlsczES
4
+ MBAGA1UEAwwJbG9jYWxob3N0MScwJQYJKoZIhvcNAQkBFhhhZG1pbkBwcm9qZWN0
5
+ aW52aWN0YS5jb20wHhcNMjMwODMwMDE1MzUzWhcNMjQwODI5MDE1MzUzWjBnMQsw
6
+ CQYDVQQGEwJVUzELMAkGA1UECAwCQ0ExDjAMBgNVBAoMBU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YhgXbYLRCEsa7q48BoSFMibmwbt07YRJXNAGjgcc7bzCV43vc/GeUgdZ
23
+ RrS1GNuzO0+S1TfvxfMBNBpoPbkeY2yHlUr+A8j6KHQw5mr3GnoOoeQTdZYK594m
24
+ N6J/gxF1emQqJoP+i+mx7iSdf5i2DmV9ACl/tyU92PKocIcsYoIevSmhtliBnsdG
25
+ R1kPkoUWuEVZujxzlIXcj0vEtOxyKJmzlBXKKO7B8U4HociBNMM41acX9WsIYdsA
26
+ QFjZTyU2DkpOCPRcBFbgQFPwfrkC93hndiByWPCkmAjeHJ0O74fnBCUP5BhmFuuc
27
+ /L0WWAVKp8HGgFmiq+i+rznJZEEEEoZClDFNkOBp4yfGZL9yZ2Ot3IRb2HNIJaj1
28
+ 69CX7ukHVHPLgiOcRSbFyuZZyqO++kWgEQm5jKlFFqGyFNpHmkGL8CGFlq7x9sF7
29
+ ONozML/sxGNw4Ubo6TAPflvl7KOd9bcYJdpODqtJgngi
30
+ -----END ENCRYPTED PRIVATE KEY-----
@@ -0,0 +1,9 @@
1
+ ---- BEGIN SSH2 PUBLIC KEY ----
2
+ Comment: "2048-bit RSA, converted by stantonwjones@darkmatter.lan from"
3
+ AAAAB3NzaC1yc2EAAAADAQABAAABAQDPJQsK/daFi/b+7bOSEJcKdzjvNJygX3BvMQ4HY+
4
+ JJaiSDyQgtwc8K85XDH0/eWyu5a6OzbadU3SkSdYP+0+uTdxfxRUCChKoASIoAaAfwB/BW
5
+ WOIdsuGPhJjYiLnPL4SScFdjUbJXGP5JOSQ6wgsRdqsDeQezUjF0CvR1CXoJaqRQt7p5T9
6
+ TlRzzuhN5Vf6BDpXBPTcNyUGKCaUwGQn2QmpXzRXrAZNb7XpzBSXdpUWm9W7U9zCFHva7J
7
+ XCuXsC9yMy3w1mpbL+oFBx7Wvic5FqwnATXjM7xBSqcG4tYzrISyn5pj13cIzzk9aEPRI3
8
+ qhV6kiA62JofiX1RkxMP+j
9
+ ---- END SSH2 PUBLIC KEY ----
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "nails_app",
3
+ "version": "0.0.0",
4
+ "description": "A basic nails application",
5
+ "main": "server.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1",
9
+ "start": "node server.js"
10
+ },
11
+ "author": "",
12
+ "license": "BSD",
13
+ "bugs": {
14
+ "url": "https://github.com/stantonwjones/nails-boilerplate/issues"
15
+ },
16
+ "config": {
17
+ "mongodbMemoryServer": {
18
+ "version": "latest"
19
+ }
20
+ },
21
+ "dependencies": {
22
+ }
23
+ }
@@ -0,0 +1,33 @@
1
+ import nails from "../../../../../index.js";
2
+ // require("../../../../../index.js").Controller;
3
+ export default class ClassbasedController extends nails.Controller {
4
+ routes = [
5
+ ["get", "./arbi/trary/testLocalRoutes", {action: 'testLocalRoutes', json: true}],
6
+ ["get", "arbi00/trary00/testLocalRoutes", {action: 'testLocalRoutes', json: true}],
7
+ ["get", "/cl4ssb4sed/arbi/trary/testLocalRoutes", {action: 'testLocalRoutes', json: true}],
8
+ ];
9
+ // DO NOT OVERRIDE CONSTRUCTOR
10
+ index(params, request, response) {
11
+ response.json({
12
+ classbased_index: true
13
+ });
14
+ }
15
+
16
+ testaction(params, request, response) {
17
+ response.json({
18
+ classbased_testaction: true
19
+ });
20
+ }
21
+
22
+ async testpromise(params, request, response) {
23
+ response.json({
24
+ classbased_testpromise: true
25
+ });
26
+ }
27
+
28
+ testLocalRoutes(params, request, response) {
29
+ return {
30
+ testLocalRoutes: true
31
+ };
32
+ }
33
+ }
@@ -0,0 +1,20 @@
1
+ import nails from "../../../../../index.js";
2
+
3
+ export default class DefaultJsonController extends nails.Controller {
4
+ json = true;
5
+ routes = [
6
+ ['get', 'arbi/trary/testautoaction'],
7
+ ['get', 'arbi/trary/testautojson', {action: 'testautojson'}],
8
+ ['get', 'arbi/trary/testjsonoverridden', {action: 'testnojson', json: false}],
9
+ ];
10
+
11
+ testautoaction(params, request, response) {
12
+ return {json_testautoaction: true};
13
+ }
14
+
15
+ testautojson(params, request, response) {
16
+ return {json_testautojson: true};
17
+ }
18
+
19
+ testnojson(params, request, response) {}
20
+ }
@@ -0,0 +1,27 @@
1
+ import nails from "../../../../../index.js";
2
+
3
+ export default class ErrorController extends nails.Controller {
4
+ // DO NOT OVERRIDE CONSTRUCTOR
5
+ index(params, request, response) {
6
+ response.json({
7
+ classbased_index: true
8
+ });
9
+ }
10
+
11
+ fivehundred(params, request, response) {
12
+ objectThatIsUndefined.attempt_to_access_field_erroneously();
13
+ return {value: "will never get here"};
14
+ }
15
+
16
+ testaction(params, request, response) {
17
+ response.json({
18
+ classbased_testaction: true
19
+ });
20
+ }
21
+
22
+ async testpromise(params, request, response) {
23
+ response.json({
24
+ classbased_testpromise: true
25
+ });
26
+ }
27
+ }