@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,296 @@
1
+ // Import the dependencies for testing
2
+ import * as chai from 'chai';
3
+ import { default as chaiHttp, request } from "chai-http";
4
+ // import chaiHttp from 'chai-http';
5
+ import { assert } from 'chai';
6
+ // import { WebSocket } from 'ws';
7
+ import WebSocket from 'ws';
8
+ // const WebSocket = require('ws');
9
+
10
+ var express_app;
11
+ // const {MongoMemoryServer} = require('mongodb-memory-server');
12
+ let mongod = null;
13
+
14
+ // Configure chai
15
+ chai.use(chaiHttp);
16
+ chai.should();
17
+
18
+ describe("Integration: Sequelize", function () {
19
+ before(async function () {
20
+ // this.timeout(30000);
21
+ try {
22
+ var nails = (await import('./services/integration/server.js')).default;
23
+ } catch (e) {
24
+ console.log("could not import server");
25
+ console.log(e);
26
+ }
27
+ console.log("got here");
28
+ express_app = nails.application;
29
+ });
30
+ describe("GET /", function () {
31
+ it('should return the expected JSON from index', function (done) {
32
+ request.execute(express_app)
33
+ .get('/')
34
+ .end((err, res) => {
35
+ res.should.have.status(200);
36
+ assert(res.text == JSON.stringify({ home_index: true }));
37
+ done();
38
+ });
39
+ });
40
+ });
41
+ describe("GET /classbased", function () {
42
+ it('should return the expected JSON from index', function (done) {
43
+ request.execute(express_app)
44
+ .get('/classbased')
45
+ .end((err, res) => {
46
+ res.should.have.status(200);
47
+ assert(res.text == JSON.stringify({ classbased_index: true }));
48
+ done();
49
+ });
50
+ });
51
+ });
52
+ describe("Get /classbased/arbi/trary/testLocalRoutes", function () {
53
+ it("Should respect the defined local route and return the expected JSON", function (done) {
54
+ request.execute(express_app)
55
+ .get('/classbased/arbi00/trary00/testLocalRoutes')
56
+ .end((err, res) => {
57
+ res.should.have.status(200);
58
+ assert(res.text == JSON.stringify({ testLocalRoutes: true }));
59
+ done();
60
+ });
61
+ });
62
+ it("Should not rewrite local route prefix and return the expected JSON", function (done) {
63
+ request.execute(express_app)
64
+ .get('/cl4ssb4sed/arbi/trary/testLocalRoutes')
65
+ .end((err, res) => {
66
+ res.should.have.status(200);
67
+ assert(res.text == JSON.stringify({ testLocalRoutes: true }));
68
+ done();
69
+ });
70
+ });
71
+ it("Should rewrite local route prefix, './' and return the expected JSON", function (done) {
72
+ request.execute(express_app)
73
+ .get('/classbased/arbi/trary/testLocalRoutes')
74
+ .end((err, res) => {
75
+ res.should.have.status(200);
76
+ assert(res.text == JSON.stringify({ testLocalRoutes: true }));
77
+ done();
78
+ });
79
+ });
80
+ });
81
+ describe("Get /defaultjson/arbi/trary", function () {
82
+ it("Should default to json if not present in route options", function(done) {
83
+ request.execute(express_app)
84
+ .get('/defaultjson/arbi/trary/testautojson')
85
+ .end((err, res) => {
86
+ res.should.have.status(200);
87
+ assert(res.text == JSON.stringify({ json_testautojson: true }));
88
+ done();
89
+ });
90
+ });
91
+ it("Should autoassign the action if not present in route options", function(done) {
92
+ request.execute(express_app)
93
+ .get('/defaultjson/arbi/trary/testautoaction')
94
+ .end((err, res) => {
95
+ res.should.have.status(200);
96
+ assert(res.text == JSON.stringify({ json_testautoaction: true }));
97
+ done();
98
+ });
99
+ });
100
+ it("Should not render json if route options explicitly say not to", function(done) {
101
+ request.execute(express_app)
102
+ .get('/defaultjson/arbi/trary/testjsonoverridden')
103
+ .end((err, res) => {
104
+ res.should.have.status(200);
105
+ assert(res.text == 'I am some arbitrary text');
106
+ done();
107
+ });
108
+ })
109
+ });
110
+ describe("GET /^\\/(\\w+)\\/(\\w+)$/i", function () {
111
+ it('should route to home_controller#testaction', function (done) {
112
+ request.execute(express_app)
113
+ .get('/home/testaction')
114
+ .end((err, res) => {
115
+ res.should.have.status(200);
116
+ assert(res.text == JSON.stringify({ home_testaction: true }));
117
+ done();
118
+ });
119
+ });
120
+ it('should route to classbased_controller#testaction', function (done) {
121
+ request.execute(express_app)
122
+ .get('/classbased/testaction')
123
+ .end((err, res) => {
124
+ res.should.have.status(200);
125
+ assert(res.text == JSON.stringify({ classbased_testaction: true }));
126
+ done();
127
+ });
128
+ });
129
+ it('should render correctly when a promise is returned', function (done) {
130
+ request.execute(express_app)
131
+ .get('/classbased/testpromise')
132
+ .end((err, res) => {
133
+ res.should.have.status(200);
134
+ assert(res.text == JSON.stringify({ classbased_testpromise: true }));
135
+ done();
136
+ });
137
+ })
138
+ });
139
+
140
+ describe("GET /error/fivehundred", function () {
141
+ it('should log the stack trace', function (done) {
142
+ request.execute(express_app)
143
+ .get('/error/fivehundred/500')
144
+ .end((err, res) => {
145
+ res.should.have.status(500);
146
+ //console.log(res.text);
147
+ //console.log(res);
148
+ //console.log(err);
149
+ done();
150
+ })
151
+ });
152
+ it('should return meaningful JSON', function (done) {
153
+ request.execute(express_app)
154
+ .get('/error/fivehundred')
155
+ .end((err, res) => {
156
+ res.should.have.status(500);
157
+ console.log("ZZZZZZZZZZ");
158
+ console.log(res.text);
159
+ //console.log(res.text);
160
+ //console.log(res);
161
+ //console.log(err);
162
+ done();
163
+ })
164
+ });
165
+ });
166
+
167
+ describe("WebSockets", function () {
168
+ it("should listen on /", function (done) {
169
+ this.timeout(2000);
170
+ var requester = request.execute(express_app).keepOpen();
171
+ var wsClient = new WebSocket("ws://localhost:3333/");
172
+
173
+ wsClient.on('close', () => done());
174
+ wsClient.on('message', (message) => {
175
+ assert(message == "It worked");
176
+ });
177
+ });
178
+ it("should listen on /voodoo", function (done) {
179
+ this.timeout(2000);
180
+ var requester = request.execute(express_app).keepOpen();
181
+ var wsClient = new WebSocket("ws://localhost:3333/voodoo");
182
+
183
+ wsClient.on('message', (message) => {
184
+ assert(message == "Voodoo worked");
185
+ });
186
+ wsClient.on('close', (code, reason) => done());
187
+ });
188
+ it("should not listen on /voodootwo", function (done) {
189
+ // TODO: this doesn't fail. Figure out why.
190
+ //done();
191
+ this.timeout(2000);
192
+ var requester = request.execute(express_app).keepOpen();
193
+ var wsClient = new WebSocket("ws://localhost:3333/voodootwo");
194
+
195
+ wsClient.on('close', (code, reason) => {
196
+ console.log('voodootwo closed', code, reason);
197
+ done();
198
+ });
199
+ debugger;
200
+ });
201
+ it("should be closed with the correct code if the action is absent");
202
+ it("should be closed with the correct code if the controller is absent");
203
+ it("should correctly parse the params");
204
+ it("should correctly handle dynamic controller and action");
205
+ });
206
+
207
+ describe("GET /json/:action", function () {
208
+ it('should render params if nothing is returned by the action',
209
+ function (done) {
210
+ request.execute(express_app)
211
+ // Route to index action.
212
+ .get('/json/testparams?testkey=testvalue')
213
+ .end((err, res) => {
214
+ res.should.have.status(200);
215
+ assert(JSON.parse(res.text).testkey == "testvalue");
216
+ done();
217
+ });
218
+ }
219
+ );
220
+ it('should render the returned object as json', function (done) {
221
+ request.execute(express_app)
222
+ .get('/json/testaction')
223
+ .end((err, res) => {
224
+ res.should.have.status(200);
225
+ assert(res.text == JSON.stringify({ json_testaction: true }));
226
+ done();
227
+ });
228
+ });
229
+ it('should asynchronously render the resolved promise as json',
230
+ function (done) {
231
+ request.execute(express_app)
232
+ .get('/json/testpromise')
233
+ .end((err, res) => {
234
+ res.should.have.status(200);
235
+ assert(res.text == JSON.stringify({ json_testpromise: true }));
236
+ done();
237
+ });
238
+ }
239
+ );
240
+ });
241
+ describe("Get /ManualRenderAsync", function () {
242
+ it("./testmanualrenderasync Should not throw an exception after manually"
243
+ + " rendering json asynchronously",
244
+ done => {
245
+ request.execute(express_app)
246
+ .get("/manualrenderasync/testmanualrenderasync")
247
+ .end((err, res) => {
248
+ res.should.have.status(200);
249
+ assert(res.text ==
250
+ JSON.stringify({ json_testmanualrenderasync: true }));
251
+ done();
252
+ });
253
+ });
254
+
255
+ it("./testmanualrenderexplicitasync Should not throw an exception after"
256
+ + " manually rendering json asynchronously using the async function"
257
+ + " tag",
258
+ done => {
259
+ request.execute(express_app)
260
+ .get("/manualrenderasync/testmanualrenderexplicitasync")
261
+ .end((err, res) => {
262
+ res.should.have.status(200);
263
+ assert(res.text ==
264
+ JSON.stringify({ json_testmanualrenderexplicitasync: true }));
265
+ done();
266
+ });
267
+ });
268
+
269
+ });
270
+ describe("Mongoose Model", function () {
271
+ beforeEach(async function () {
272
+ // Used to initialize mongod here
273
+ });
274
+ afterEach(async function () {
275
+ //await mongod.stop();
276
+ });
277
+ it('should save to the correct database', function (done) {
278
+ let dogName = "Penny";
279
+ let dogId = null;
280
+ request.execute(express_app)
281
+ .get(`/modeltest/createdog?name=${dogName}`)
282
+ .end((err, res) => {
283
+ res.should.have.status(200);
284
+ dogId = res.text.replaceAll('"', '');
285
+ request.execute(express_app)
286
+ .get(`/modeltest/getdogbyid?id=${dogId}`)
287
+ .end((err, res) => {
288
+ assert.equal(
289
+ res.text, JSON.stringify({ name: dogName, good: true }));
290
+ done();
291
+ });
292
+ });
293
+ });
294
+
295
+ });
296
+ });
@@ -0,0 +1,60 @@
1
+ import * as chai from 'chai';
2
+ import { default as chaiHttp, request } from "chai-http";
3
+ // import chaiHttp from 'chai-http';
4
+ import { assert } from 'chai';
5
+ // import { WebSocket } from 'ws';
6
+ import WebSocket from 'ws';
7
+ // const WebSocket = require('ws');
8
+
9
+ var express_app;
10
+
11
+ // Configure chai
12
+ chai.use(chaiHttp);
13
+ chai.should();
14
+
15
+ describe("Integration", function () {
16
+ before(async function () {
17
+ try {
18
+ var nails = (await import('./services/integration_sequelize/server.js')).default;
19
+ } catch (e) {
20
+ console.log("could not import server");
21
+ console.log(e);
22
+ }
23
+ console.log("got here");
24
+ express_app = nails.application;
25
+ });
26
+ describe("GET /", function () {
27
+ it('should return the expected JSON from index', function (done) {
28
+ request.execute(express_app)
29
+ .get('/')
30
+ .end((err, res) => {
31
+ if (err) console.error(err);
32
+ res.should.have.status(200);
33
+ assert(res.text == JSON.stringify({ home_index: true }));
34
+ done();
35
+ });
36
+ });
37
+ });
38
+ describe("/listowners", function() {
39
+ it('should return an empty array if no owners', function(done) {
40
+ request.execute(express_app)
41
+ .get('/listowners')
42
+ .end((err, res) => {
43
+ res.should.have.status(200);
44
+ assert(JSON.parse(res.text).length == 0);
45
+ done();
46
+ });
47
+ })
48
+ })
49
+ describe("/listowneddogs", function() {
50
+ it('should return an empty array if no owned dogs', function(done) {
51
+ request.execute(express_app)
52
+ .get('/listowneddogs')
53
+ .end((err, res) => {
54
+ res.should.have.status(200);
55
+ assert(JSON.parse(res.text).length == 0);
56
+ done();
57
+ });
58
+ })
59
+ })
60
+ });
@@ -0,0 +1,20 @@
1
+ version=$1
2
+ if [ "$version" == "" ]; then
3
+ version="live"
4
+ fi
5
+
6
+ if [ "$version" != "live" ] &&
7
+ [ "$version" != "development" ] &&
8
+ [ "$version" != "staging_qa" ] &&
9
+ [ "$version" != "staging_prod" ] &&
10
+ [ "$version" != "production" ]; then
11
+ echo "$version is not a valid version"
12
+ exit 1
13
+ fi
14
+
15
+ # TODO: make sure we're on the master branch
16
+ git pull origin master
17
+ git tag -d $version
18
+ git push origin --delete $version
19
+ git tag $version
20
+ git push origin $version
@@ -0,0 +1,74 @@
1
+ # make sure no one can run the script on their local machine
2
+ stage=$1
3
+ if [ "$stage" = "" ]; then
4
+ stage="live"
5
+ fi
6
+
7
+ if [ "$stage" != "live" ] &&
8
+ [ "$stage" != "development" ] &&
9
+ [ "$stage" != "staging_qa" ] &&
10
+ [ "$stage" != "staging_prod" ] &&
11
+ [ "$stage" != "production" ]; then
12
+ echo "$stage is not a valid release stage"
13
+ exit 1
14
+ fi
15
+
16
+ current_hostname=$(hostname)
17
+
18
+ # TODO: find a better way to do this rather than listing them all out. Maybe some kind of dynamic list checking.
19
+ com_suffix=".com"
20
+ dev_suffix=".dev"
21
+ app_suffix=".app"
22
+ net_suffix=".net"
23
+ org_suffix=".org"
24
+
25
+
26
+ if [[ $current_hostname != *$com_suffix &&
27
+ $current_hostname != *$dev_suffix &&
28
+ $current_hostname != *$app_suffix &&
29
+ $current_hostname != *$net_suffix &&
30
+ $current_hostname != *$org_suffix ]]; then
31
+ echo "This script cannot be run on your local machine and must be run on a server"
32
+ exit 1
33
+ fi
34
+
35
+ echo "Running checkout_live.sh version $stage on `date`"
36
+
37
+ # check if the repo is up to date by comparing hashes for the live tag
38
+ remote_hash=$(git ls-remote --tags origin "$stage" | awk '{ print $1 }')
39
+ local_hash=$(git rev-list -n 1 $stage)
40
+
41
+ # get the latest updates from the repo if out of date
42
+ if [ $remote_hash != $local_hash ]; then
43
+ date=`date`
44
+ echo "Checkout $NAME running at: $date"
45
+ echo "Checkout $NAME running at: $date" 1>&2 # write date to stderr as well
46
+ echo "`dirname $0`"
47
+ echo "`dirname $0`" 1>&2
48
+ git fetch --all --tags --force
49
+ git checkout tags/$stage
50
+ npm install
51
+ else
52
+ echo "Repository is not out of date. Exiting..."
53
+ exit 0
54
+ fi
55
+
56
+ # TODO: add conditional when real test added
57
+
58
+ # test
59
+ npm test # currently an echo noop
60
+
61
+ # restart parkway
62
+ /usr/sbin/service $NAME-$stage restart
63
+
64
+ changelog=`git log $local_hash..$remote_hash --oneline`
65
+
66
+ # send email
67
+ user=$(whoami)
68
+ message="The latest $NAME changes have been deployed to $stage at $date by $user\n$changelog"
69
+ recipient="eng@projectinvicta.com"
70
+ subject="Automated deploy of $NAME: $stage"
71
+ echo $message | mail -s "$subject" $recipient
72
+ echo "Mail sent"
73
+
74
+ exit 0
@@ -0,0 +1,6 @@
1
+ import nails from 'nails-boilerplate';
2
+
3
+ // See self-documented config files
4
+ import service_config from '../config/service.js';
5
+
6
+ (await nails( service_config )).startServer();
@@ -0,0 +1,16 @@
1
+ SCRIPT_DIR=$(dirname "$0")
2
+ echo "Script directory (relative): $SCRIPT_DIR"
3
+
4
+ COMMAND=$1
5
+ if [[ -z "${COMMAND}" ]]; then
6
+ COMMAND=start
7
+ else
8
+ echo "COMMAND is NOT empty."
9
+ fi
10
+
11
+
12
+ SCRIPT_PATH=$(readlink -f "$0")
13
+ SCRIPT_DIR=$(dirname "$SCRIPT_PATH")
14
+ echo "Script directory (absolute, resolved): $SCRIPT_DIR"
15
+
16
+ npm --prefix=$SCRIPT_DIR/.. run $COMMAND -- $2 $3 $4 $5 $6 $7 $8 $9
@@ -0,0 +1,4 @@
1
+ export async function fetchReadme() {
2
+ return fetch('/public/README.xml')
3
+ .then(response => response.text());
4
+ }
@@ -0,0 +1,19 @@
1
+ let DB_ADDRESS = process.env.NAILS_SQLITE_DB_FILE;
2
+ if (!DB_ADDRESS) DB_ADDRESS = 'sqlite://' + import.meta.dirname + '/development.db';
3
+
4
+ export default {
5
+ /** Mongoose Connector */
6
+ // connector: 'mongoose_connector.js',
7
+ // url: 'mongodb://localhost',
8
+ // port: '27017',
9
+
10
+ /** Mongoose Memory Server Connector */
11
+ // connector: 'mongoose_mem_connector.js',
12
+ // database: 'development',
13
+
14
+ /** Sequelize Connector */
15
+ connector: 'sequelize_connector.js',
16
+ address: process.env.NAILS_RELEASE_STAGE == 'test'
17
+ ? 'sqlite::memory:'
18
+ : DB_ADDRESS,
19
+ }
@@ -0,0 +1,59 @@
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
+ export default {
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
+ }
@@ -0,0 +1,38 @@
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
+ export default [
21
+ // Routes the root request to index.html, as well as all other requests to static
22
+ ['get', "/", {controller: 'home'}],
23
+ // Routes all requests starting with /public as static requests to the public folder.
24
+ ['get', '/public', {public: true}],
25
+
26
+ // A test route which routes the first part of pathname to controller and the second to the action
27
+ // ['get', /^\/(\w+)\/(\w+)$/i, {0: 'controller', 1: 'action'}],
28
+
29
+ // Maps the first two parts of the path to controller and action, and the third to the id parameter
30
+ // ['get', "/:controller/:action/:id"],
31
+
32
+ // For all other GET requests, render HomeController#index
33
+ ['get', '/:catchall', {controller: 'home'}],
34
+
35
+ // Defines a WebSocket handler
36
+ // ['ws', "/:controller/:action/:id"]
37
+ ];
38
+
@@ -0,0 +1,45 @@
1
+ // Initializes application before server starts
2
+ // Each of these is REQUIRED
3
+ import routes from './routes.js';
4
+ import mimes from './mimes.js';
5
+ import db from './db.js';
6
+
7
+ import path from 'node:path';
8
+ var SERVER_ROOT = path.resolve(import.meta.dirname, '..');
9
+ var APP_ROOT = path.resolve(SERVER_ROOT, 'server');
10
+
11
+ // Only for reading the certificates for SSL
12
+ import fs from 'node:fs';
13
+ const PRIVATE_KEY_FILE = fs.readFileSync(`${import.meta.dirname}/ssl/key.pem`);
14
+ const CERTIFICATE_FILE = fs.readFileSync(`${import.meta.dirname}/ssl/certificate.pem`);
15
+
16
+ var config = {
17
+ APP_ROOT: APP_ROOT,
18
+ // root directory for delivering static assets
19
+ PUBLIC_ROOT: SERVER_ROOT + '/public',
20
+ CONTROLLERS_ROOT: APP_ROOT + '/controllers',
21
+ VIEWS_ROOT: APP_ROOT + '/views',
22
+ MODELS_ROOT: APP_ROOT + '/models',
23
+ SERVER_ROOT: SERVER_ROOT,
24
+
25
+ ENABLE_HTTP: true,
26
+ //IP: "0.0.0.0",
27
+ PORT: 3333,
28
+
29
+ // Uncomment these to use serverside react view engine.
30
+ //VIEW_ENGINE: require('express-react-views').createEngine(),
31
+ //VIEW_ENGINE_EXT: 'jsx',
32
+
33
+ // For HTTPS
34
+ ENABLE_HTTPS: true,
35
+ SSL_PORT: 3334,
36
+ PRIVATE_KEY: PRIVATE_KEY_FILE,
37
+ CERTIFICATE: CERTIFICATE_FILE,
38
+ };
39
+
40
+ export default {
41
+ config,
42
+ routes,
43
+ mimes,
44
+ db
45
+ }
@@ -0,0 +1,22 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDrzCCApegAwIBAgIUR04h3qlfhW5SYQrnm0VjDSLQrwUwDQYJKoZIhvcNAQEL
3
+ BQAwZzELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMQ4wDAYDVQQKDAVOYWlsczES
4
+ MBAGA1UEAwwJbG9jYWxob3N0MScwJQYJKoZIhvcNAQkBFhhhZG1pbkBwcm9qZWN0
5
+ aW52aWN0YS5jb20wHhcNMjMwODMwMDE1MzUzWhcNMjQwODI5MDE1MzUzWjBnMQsw
6
+ CQYDVQQGEwJVUzELMAkGA1UECAwCQ0ExDjAMBgNVBAoMBU5haWxzMRIwEAYDVQQD
7
+ DAlsb2NhbGhvc3QxJzAlBgkqhkiG9w0BCQEWGGFkbWluQHByb2plY3RpbnZpY3Rh
8
+ LmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALP54rGDg1Lo7FSs
9
+ q4xvvOeisWLJzbTZN+hsxL3ytcxvk3oidVoZDDfkDJ1QBoPFjIyHlJZCvC6mJMeY
10
+ 3Nibn1zZAtsST84DCYS8c0bQAbEUc+OwSmNpVLQElnTAKyoY/7izj579p5uR7WLD
11
+ mSk2c4igeqjOAQn/rrC3Lr+Dr6HA3lcEQD7g87OQz7JCRY6p5E980HO81gknnxod
12
+ veQogbreiQ+MOwC9qPOwfJjAX/qkTWc1SXIiV2SskoIANTbGujMHZZZIaY5a5oWZ
13
+ 9pAKR0basSAjECMmr1/UCKGZeot0AZRKMBSHp6mlHlE5LLFIH56PaRTguSBhsrle
14
+ BWcuUcUCAwEAAaNTMFEwHQYDVR0OBBYEFCigQMRd+cKymXdHgew3JMEcokv0MB8G
15
+ A1UdIwQYMBaAFCigQMRd+cKymXdHgew3JMEcokv0MA8GA1UdEwEB/wQFMAMBAf8w
16
+ DQYJKoZIhvcNAQELBQADggEBAD5ZtQ3XLBzOiJoICcRA0evC/59gt2kKw1owOLJy
17
+ Ji4rtoWCis8nr3R1U62KUENZ//WRy09uNPHfjsaFwuvgO+GWn53Q3breCEO1r2lH
18
+ z5qWUAdb7WpoZWZJdj6wZoJQeKQoK8fVCVNNPNHwhZRK2P2SWhn5v/7Qco5JMP8+
19
+ qpIbAzjKOoHiz1238JYXJ5G1tMVMfVvQpC1E+KM9p9Bohtuc51pYMssT31WPBoOv
20
+ TBcIarZ8ri6VBAh/+aUpce0BqOEtZ1oa6Mnd2w5GeqgtV+G7ir5g0uXZjOFrh5A7
21
+ c6J3QmpeF3kfs+Ggsxh/fRrnK1VDDtWQ/mF/3Jrq43JoP0E=
22
+ -----END CERTIFICATE-----