nails-boilerplate 2.0.1 → 2.0.3

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 (29) hide show
  1. package/lib/nails.js +6 -2
  2. package/lib/sequelize_connector.js +1 -1
  3. package/package.json +1 -1
  4. package/spec/services/integration_sequelize/README.md +5 -0
  5. package/spec/services/integration_sequelize/client/css/styles.css +0 -0
  6. package/spec/services/integration_sequelize/client/download.jpg +0 -0
  7. package/spec/services/integration_sequelize/client/favicon.ico +0 -0
  8. package/spec/services/integration_sequelize/client/index.html +9 -0
  9. package/spec/services/integration_sequelize/client/js/client.js +0 -0
  10. package/spec/services/integration_sequelize/client/js/components/app.jsx +15 -0
  11. package/spec/services/integration_sequelize/config/db.js +4 -0
  12. package/spec/services/integration_sequelize/config/mimes.js +61 -0
  13. package/spec/services/integration_sequelize/config/routes.js +25 -0
  14. package/spec/services/integration_sequelize/config/service.js +48 -0
  15. package/spec/services/integration_sequelize/config/ssl/certificate.pem +22 -0
  16. package/spec/services/integration_sequelize/config/ssl/csr.csr +17 -0
  17. package/spec/services/integration_sequelize/config/ssl/key.pem +28 -0
  18. package/spec/services/integration_sequelize/config/ssl/private_key.pem +30 -0
  19. package/spec/services/integration_sequelize/config/ssl/public_key.pem +9 -0
  20. package/spec/services/integration_sequelize/package.json +23 -0
  21. package/spec/services/integration_sequelize/server/controllers/default_json_controller.js +21 -0
  22. package/spec/services/integration_sequelize/server/controllers/home_controller.js +39 -0
  23. package/spec/services/integration_sequelize/server/models/dog.js +7 -0
  24. package/spec/services/integration_sequelize/server/models/owner.js +10 -0
  25. package/spec/services/integration_sequelize/server/views/defaultjson/testnojson.ejs +1 -0
  26. package/spec/services/integration_sequelize/server/views/testreact/testreact.ejs +15 -0
  27. package/spec/services/integration_sequelize/server.js +9 -0
  28. package/spec/services.integration_sequelize.spec.js +67 -0
  29. package/templates/config/service.js +1 -1
package/lib/nails.js CHANGED
@@ -39,6 +39,7 @@ nails.application = express_app;
39
39
  nails.Controller = Controller;
40
40
  nails.Model = ModelV2;
41
41
  nails.events = new EventEmitter();
42
+ nails._dbConnector = null;
42
43
 
43
44
  async function configure( app_config ) {
44
45
  express_app.set('nails_config', application);
@@ -72,11 +73,13 @@ async function configure( app_config ) {
72
73
 
73
74
  console.log("Instantiating DBConnector and Connecting to DB...");
74
75
  // Try to instantiate DBConnector
75
- let dbConnector = new DBConnector();
76
+ const dbConnector = new DBConnector();
77
+ nails._dbConnector = dbConnector;
76
78
  await dbConnector.connect(app_config.db);
77
79
  console.log("Generating model superclass...");
78
80
  ModelV2.setConnector(dbConnector);
79
81
  await init_models_v2(app_config.config.MODELS_ROOT);
82
+ console.log("Done importing models")
80
83
  await dbConnector.afterInitialization();
81
84
  console.log("DB Connection complete");
82
85
 
@@ -166,7 +169,8 @@ async function init_models_v2(abs_path) {
166
169
  // We just need to import each model once so the generateSuperclass
167
170
  // method is called at least once for each model.
168
171
  let modelClass = (await import(abs_path)).default;
169
- console.log('imported model:', modelClass.name);
172
+ if (modelClass && modelClass.name) console.log('imported model:', modelClass.name);
173
+ else console.warn("No model found at:", abs_path);
170
174
  // // Constructor function was provided
171
175
  // if (!superclass.isPrototypeOf(subclass))
172
176
  // return superclass.extend(subclass);
@@ -21,6 +21,6 @@ export default class SequelizeConnector extends DbConnector {
21
21
 
22
22
  async afterInitialization() {
23
23
  console.log("SEQUELIZE::Writing changes to SQL Database");
24
- await this.sequelize.sync({alter: true});
24
+ await this.sequelize.sync({alter: {drop: false}});
25
25
  }
26
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nails-boilerplate",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "A node.js webserver scaffold",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -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>
@@ -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,4 @@
1
+ export default {
2
+ connector: 'sequelize_connector.js',
3
+ address: 'sqlite::memory:',
4
+ }
@@ -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,25 @@
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
+ ];
24
+
25
+ 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
+ CQYDVQQGEwJVUzELMAkGA1UECAwCQ0ExDjAMBgNVBAoMBU5haWxzMRIwEAYDVQQD
7
+ DAlsb2NhbGhvc3QxJzAlBgkqhkiG9w0BCQEWGGFkbWluQHByb2plY3RpbnZpY3Rh
8
+ LmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALP54rGDg1Lo7FSs
9
+ q4xvvOeisWLJzbTZN+hsxL3ytcxvk3oidVoZDDfkDJ1QBoPFjIyHlJZCvC6mJMeY
10
+ 3Nibn1zZAtsST84DCYS8c0bQAbEUc+OwSmNpVLQElnTAKyoY/7izj579p5uR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PwfrkC93hndiByWPCkmAjeHJ0O74fnBCUP5BhmFuuc
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,21 @@
1
+ import nails from "../../../../../index.js";
2
+ import Dog from "../models/dog.js";
3
+ import Owner from "../models/owner.js";
4
+
5
+ export default class DefaultJsonController extends nails.Controller {
6
+ json = true;
7
+ routes = [
8
+ ['get', '/listowners'],
9
+ ['get', '/listowneddogs'],
10
+ ];
11
+
12
+ async listowners(params, request, response) {
13
+ return await Owner.findAll();
14
+ }
15
+
16
+ async listowneddogs(params, request, response) {
17
+ // await nails._dbConnector.afterInitialization();
18
+ // await Dog.sync({alter: true});
19
+ return await Dog.findAll();
20
+ }
21
+ }
@@ -0,0 +1,39 @@
1
+ export default function HomeController() {
2
+ this.index = function(params, request, response) {
3
+ console.log("HOME::INDEX");
4
+ response.json({
5
+ home_index: true
6
+ });
7
+ };
8
+ this.testaction = function(params, request, response) {
9
+ response.json({
10
+ home_testaction: true
11
+ });
12
+ }
13
+ this.test_ejs = function() {
14
+ };
15
+ /*
16
+ this.public_index = function(params, request, response) {
17
+ response.public({path: 'index.html'});
18
+ };
19
+ this.json = function(params, request, response) {
20
+ response.json({test: 'json'});
21
+ };
22
+ // By setting a method to asynchronous, Nails will wait for an
23
+ // explicit response to the client. Otherwise, it will attempt
24
+ // to respond with a view immediately after the action terminates.
25
+ this.json.async = true;
26
+
27
+ this.test_model = function(params, request, response) {
28
+ var u = new User();
29
+ u.set('created_at', (new Date()).getTime());
30
+ u.save();
31
+ response.json({new_user_id: u.id.toString()});
32
+ };
33
+ this.test_id_template = function(params, request, response) {
34
+ var varz = {};
35
+ varz.id = params.id || "no id set";
36
+ response.render('test_id', varz);
37
+ };
38
+ */
39
+ }
@@ -0,0 +1,7 @@
1
+ import nails from '../../../../../index.js';
2
+ import { DataTypes } from 'sequelize';
3
+ const dogSchema = {
4
+ good: DataTypes.BOOLEAN,
5
+ name: DataTypes.STRING,
6
+ };
7
+ export default class Dog extends new nails.Model("Dog", dogSchema) {};
@@ -0,0 +1,10 @@
1
+ import nails from '../../../../../index.js';
2
+ import { DataTypes } from 'sequelize';
3
+ import Dog from './dog.js';
4
+ const ownerSchema = {
5
+ name: DataTypes.STRING,
6
+ };
7
+ class Owner extends new nails.Model("Owner", ownerSchema) {};
8
+ Owner.hasMany(Dog);
9
+ await Dog.sync();
10
+ export default Owner;
@@ -0,0 +1,15 @@
1
+ /* jshint esversion: 6 */
2
+ var React = require('react');
3
+
4
+ class TestReact extends React.Component {
5
+ render() {
6
+ return (
7
+ <html>
8
+ <head><title>react</title></head>
9
+ <body>react works!</body>
10
+ </html>
11
+ );
12
+ }
13
+ }
14
+
15
+ module.exports = TestReact;
@@ -0,0 +1,9 @@
1
+ // var nails = require('../../../index.js');
2
+ import nails from '../../../index.js';
3
+ import service_config from './config/service.js';
4
+
5
+ // See self-documented config files
6
+ // var service_config = require('./config/service.js');
7
+ // console.log("starting server")
8
+ (await nails( service_config )).startServer();
9
+ export default nails; // export nails for testing
@@ -0,0 +1,67 @@
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
+ // const {MongoMemoryServer} = require('mongodb-memory-server');
11
+ let mongod = null;
12
+
13
+ // Configure chai
14
+ chai.use(chaiHttp);
15
+ chai.should();
16
+
17
+ describe("Integration", function () {
18
+ before(async function () {
19
+ try {
20
+ var nails = (await import('./services/integration_sequelize/server.js')).default;
21
+ } catch (e) {
22
+ console.log("could not import server");
23
+ console.log(e);
24
+ }
25
+ console.log("got here");
26
+ express_app = nails.application;
27
+ return new Promise((resolve, reject) => {
28
+ nails.events.on("ready", () => {
29
+ console.log("ready was emitted!");
30
+ resolve();
31
+ });
32
+ });
33
+ });
34
+ describe("GET /", function () {
35
+ it('should return the expected JSON from index', function (done) {
36
+ request.execute(express_app)
37
+ .get('/')
38
+ .end((err, res) => {
39
+ res.should.have.status(200);
40
+ assert(res.text == JSON.stringify({ home_index: true }));
41
+ done();
42
+ });
43
+ });
44
+ });
45
+ describe("/listowners", function() {
46
+ it('should return an empty array if no owners', function(done) {
47
+ request.execute(express_app)
48
+ .get('/listowners')
49
+ .end((err, res) => {
50
+ res.should.have.status(200);
51
+ assert(JSON.parse(res.text).length == 0);
52
+ done();
53
+ });
54
+ })
55
+ })
56
+ describe("/listowneddogs", function() {
57
+ it('should return an empty array if no owned dogs', function(done) {
58
+ request.execute(express_app)
59
+ .get('/listowneddogs')
60
+ .end((err, res) => {
61
+ res.should.have.status(200);
62
+ assert(JSON.parse(res.text).length == 0);
63
+ done();
64
+ });
65
+ })
66
+ })
67
+ });
@@ -19,7 +19,7 @@ var config = {
19
19
  PUBLIC_ROOT: SERVER_ROOT + '/public',
20
20
  CONTROLLERS_ROOT: APP_ROOT + '/controllers',
21
21
  VIEWS_ROOT: APP_ROOT + '/views',
22
- //MODELS_ROOT: APP_ROOT + '/models',
22
+ MODELS_ROOT: APP_ROOT + '/models',
23
23
  SERVER_ROOT: SERVER_ROOT,
24
24
 
25
25
  ENABLE_HTTP: true,