nails-boilerplate 0.14.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/lib/init.js +27 -19
- package/bin/lib/nails.js +3 -2
- package/index.js +2 -1
- package/lib/application.js +12 -5
- package/lib/collection.js +1 -3
- package/lib/controller.js +7 -4
- package/lib/firebase_connector.js +6 -3
- package/lib/model.js +5 -4
- package/lib/model_v2.js +1 -3
- package/lib/mongodb_connector.js +5 -4
- package/lib/mongoose_connector.js +3 -2
- package/lib/mongoose_mem_connector.js +16 -11
- package/lib/nails.js +36 -19
- package/lib/router.js +29 -14
- package/lib/sqlite3_connector.js +6 -3
- package/package.json +5 -3
- package/spec/controller.spec.js +21 -20
- package/spec/model.spec.js +3 -3
- package/spec/model_v2.spec.js +3 -3
- package/spec/mongodb_connector.spec.js +2 -2
- package/spec/mongodb_connector.util.js +3 -3
- package/spec/mongoose_connector.util.js +3 -3
- package/spec/router.spec.js +6 -4
- package/spec/services/integration/config/db.js +1 -1
- package/spec/services/integration/config/mimes.js +1 -1
- package/spec/services/integration/config/routes.js +1 -1
- package/spec/services/integration/config/service.js +21 -14
- package/spec/services/integration/package.json +6 -0
- package/spec/services/integration/{app → server}/controllers/classbased_controller.js +3 -5
- package/spec/services/integration/{app → server}/controllers/error_controller.js +4 -6
- package/spec/services/integration/{app → server}/controllers/home_controller.js +1 -1
- package/spec/services/integration/{app → server}/controllers/json_controller.js +3 -5
- package/spec/services/integration/{app → server}/controllers/manualrenderasync_controller.js +2 -5
- package/spec/services/integration/{app → server}/controllers/modeltest_controller.js +4 -4
- package/spec/services/integration/{app → server}/controllers/websocket_controller.js +3 -3
- package/spec/services/integration/server/models/dog.js +6 -0
- package/spec/services/integration/server.js +7 -5
- package/spec/services.integration.spec.js +48 -34
- package/templates/bin/promote.sh +20 -0
- package/templates/bin/rollout.sh +74 -0
- package/templates/bin/server.js +6 -0
- package/templates/client/README.xml +215 -0
- package/templates/client/css/styles.css +17 -0
- package/templates/client/js/client.js +1 -0
- package/templates/client/src/AboutPage.jsx +9 -0
- package/templates/client/src/HomePage.jsx +9 -0
- package/templates/client/src/Layout.jsx +78 -0
- package/templates/client/src/ReadmePage.jsx +7 -0
- package/templates/client/src/app.jsx +29 -0
- package/templates/client/src/components/ReadmeLoader.jsx +13 -0
- package/templates/common/readme_fetcher.js +4 -0
- package/templates/config/db.js +1 -1
- package/templates/config/mimes.js +1 -3
- package/templates/config/routes.js +6 -4
- package/templates/config/service.js +17 -12
- package/templates/package-lock.json +8626 -0
- package/templates/package.json +20 -5
- package/templates/{app → server}/controllers/home_controller.js +3 -2
- package/templates/server/models/user.js +9 -0
- package/templates/server/views/home/index.ejs +14 -0
- package/templates/server/views/partials/javascripts.ejs +1 -0
- package/templates/server/views/partials/reactapp.ejs +1 -0
- package/templates/server/views/partials/styles.ejs +2 -0
- package/templates/spec/home_controller.spec.js +9 -5
- package/templates/vite.config.ts +38 -0
- package/spec/services/integration/app/models/dog.js +0 -6
- package/templates/app/models/user.js +0 -7
- package/templates/app/views/home/index.ejs +0 -8
- package/templates/app/views/home/index.jsx +0 -52
- package/templates/public/css/styles.css +0 -0
- package/templates/public/js/client.js +0 -0
- package/templates/public/js/components/app.jsx +0 -14
- package/templates/server.js +0 -5
- /package/spec/services/integration/{public → client}/css/styles.css +0 -0
- /package/spec/services/integration/{public → client}/download.jpg +0 -0
- /package/spec/services/integration/{public → client}/favicon.ico +0 -0
- /package/spec/services/integration/{public → client}/index.html +0 -0
- /package/spec/services/integration/{public → client}/js/client.js +0 -0
- /package/spec/services/integration/{public → client}/js/components/app.jsx +0 -0
- /package/spec/services/integration/{app → server}/controllers/mjs_controller.mjs +0 -0
- /package/spec/services/integration/{app/views/testreact/testreact.jsx → server/views/testreact/testreact.ejs} +0 -0
- /package/templates/{public → client}/download.jpg +0 -0
- /package/templates/{public → client}/favicon.ico +0 -0
- /package/templates/{public → client}/index.html +0 -0
package/bin/lib/init.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
// Install script which adds commands for running nails
|
|
2
2
|
// to the path
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
// TODO: wrench is deprecated. check out node-fs-extra
|
|
6
|
+
import wrench from 'wrench';
|
|
7
|
+
// var wrench = require('wrench');
|
|
8
|
+
import {exec} from 'child_process';
|
|
9
|
+
// var exec = require('child_process').exec;
|
|
6
10
|
var args = process.argv.slice(2);
|
|
7
11
|
|
|
8
12
|
var appName = args[0];
|
|
@@ -40,35 +44,39 @@ function isNailsApp( originalDir, directory ) {
|
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
function createApp( name ) {
|
|
43
|
-
var templateRoot =
|
|
47
|
+
var templateRoot = path.resolve(import.meta.dirname, "../../templates");
|
|
44
48
|
if (!fs.existsSync(name)) fs.mkdirSync(name);
|
|
45
|
-
fs.open(name + '/NAILS','w',
|
|
49
|
+
fs.open(name + '/NAILS','w', 0o666, function(err, fd) {
|
|
46
50
|
if (err) throw err;
|
|
47
51
|
fs.writeFileSync(name + '/NAILS', '/* This marks the root of the NAILS app */');
|
|
48
52
|
fs.closeSync(fd);
|
|
49
53
|
|
|
50
|
-
wrench.copyDirSyncRecursive(templateRoot
|
|
51
|
-
wrench.copyDirSyncRecursive(templateRoot
|
|
52
|
-
wrench.copyDirSyncRecursive(templateRoot
|
|
54
|
+
wrench.copyDirSyncRecursive(path.resolve(templateRoot, './server'), name + '/server');
|
|
55
|
+
wrench.copyDirSyncRecursive(path.resolve(templateRoot, './client'), name + '/client');
|
|
56
|
+
wrench.copyDirSyncRecursive(path.resolve(templateRoot, './config'), name + '/config');
|
|
57
|
+
wrench.copyDirSyncRecursive(path.resolve(templateRoot, './common'), name + '/common');
|
|
58
|
+
wrench.copyDirSyncRecursive(path.resolve(templateRoot, './spec'), name + '/spec');
|
|
59
|
+
wrench.copyDirSyncRecursive(path.resolve(templateRoot, './bin'), name + '/bin');
|
|
53
60
|
|
|
54
61
|
checkWrites();
|
|
55
62
|
});
|
|
56
63
|
|
|
57
64
|
//fs.copyFileSync(templateRoot + '/.babelrc', name + '/.babelrc');
|
|
65
|
+
fs.copyFileSync(path.resolve(templateRoot, './vite.config.ts'), name + '/vite.config.ts');
|
|
58
66
|
|
|
59
|
-
fs.open(name + '/server.js','w',
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
});
|
|
67
|
+
// fs.open(name + 'bin/server.js','w', 0o666, function(err, fd) {
|
|
68
|
+
// if (err) throw err;
|
|
69
|
+
// fs.readFile(path.resolve(templateRoot,'./bin/server.js'), 'utf8', function(err, data) {
|
|
70
|
+
// if (err) throw err;
|
|
71
|
+
// fs.writeFileSync( name + '/server.js', data );
|
|
72
|
+
// fs.closeSync(fd);
|
|
73
|
+
// checkWrites();
|
|
74
|
+
// });
|
|
75
|
+
// });
|
|
68
76
|
|
|
69
77
|
//TODO: use toJSON to dynamically create package.json
|
|
70
78
|
//TODO: install dependencies after writing package.json
|
|
71
|
-
fs.open(name + '/package.json','w',
|
|
79
|
+
fs.open(name + '/package.json','w', 0o666, function(err, fd) {
|
|
72
80
|
if (err) throw err;
|
|
73
81
|
fs.readFile(templateRoot + '/package.json', 'utf8', function(err, data) {
|
|
74
82
|
if (err) throw err;
|
|
@@ -82,7 +90,7 @@ function createApp( name ) {
|
|
|
82
90
|
var numWrites = 0;
|
|
83
91
|
function checkWrites() {
|
|
84
92
|
numWrites++;
|
|
85
|
-
if (numWrites ==
|
|
93
|
+
if (numWrites == 2) {
|
|
86
94
|
console.log("Initialized new Nails Application successfully");
|
|
87
95
|
console.log("installing nails locally");
|
|
88
96
|
// change into app directory
|
package/bin/lib/nails.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// The entry point for the nails executable
|
|
4
|
-
|
|
4
|
+
import { exec } from 'child_process';
|
|
5
|
+
// var exec = require('child_process').exec;
|
|
5
6
|
console.log('nailsargs are: ', process.argv);
|
|
6
7
|
var args = process.argv.splice(2);
|
|
7
8
|
|
|
8
9
|
// TODO: print version and help info if called with no arguments
|
|
9
10
|
|
|
10
|
-
var command = 'node ' +
|
|
11
|
+
var command = 'node ' + import.meta.dirname + '/' + args[0] + '.js';
|
|
11
12
|
|
|
12
13
|
for (var i = 1; i < args.length; i++) {
|
|
13
14
|
command = command + " " + args[i];
|
package/index.js
CHANGED
package/lib/application.js
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
|
-
const bodyParser = require('body-parser');
|
|
1
|
+
// const bodyParser = require('body-parser');
|
|
2
|
+
import pkg from 'body-parser';
|
|
3
|
+
const {urlencoded, json} = pkg;
|
|
4
|
+
import express from 'express';
|
|
5
|
+
import expressWs from 'express-ws';
|
|
2
6
|
|
|
3
7
|
/**
|
|
4
8
|
* Singleton express application.
|
|
5
9
|
*/
|
|
6
|
-
var express = require('express');
|
|
10
|
+
// var express = require('express');
|
|
7
11
|
var app = express();
|
|
12
|
+
// TODO: this has to be done before routes in order to work. Can consider allowing the config to turn this off
|
|
13
|
+
// expressWs(app);
|
|
8
14
|
// Parse application/x-www-form-urlencoded
|
|
9
|
-
app.use(
|
|
15
|
+
app.use(urlencoded({ limit: '2mb', extended: false }));
|
|
10
16
|
// Parse application/json
|
|
11
|
-
app.use(
|
|
12
|
-
module.exports = app;
|
|
17
|
+
app.use(json({limit: '2mb'}));
|
|
13
18
|
|
|
14
19
|
app.Router = express.Router;
|
|
15
20
|
app.static = express.static;
|
|
21
|
+
|
|
22
|
+
export default app;
|
package/lib/collection.js
CHANGED
package/lib/controller.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
// const fs = require('fs');
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import events from 'node:events';
|
|
4
|
+
// const events = require('events');
|
|
5
|
+
import application from './application.js';
|
|
6
|
+
// const application = require('./application');
|
|
4
7
|
|
|
5
8
|
var router;
|
|
6
9
|
var controller_proto;
|
|
@@ -144,4 +147,4 @@ error_codes.forEach((ec) => {
|
|
|
144
147
|
|
|
145
148
|
});
|
|
146
149
|
|
|
147
|
-
|
|
150
|
+
export default Controller;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
// TODO: multiple async requests here... need to
|
|
2
2
|
// consider how this will be used by the models
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import {EventEmitter} from 'node:events';
|
|
4
|
+
// var EventEmitter = require('events').EventEmitter;
|
|
5
|
+
import { MongoClient } from 'mongodb';
|
|
6
|
+
// const MongoClient = require('mongodb').MongoClient;
|
|
7
|
+
// const test = require('assert');
|
|
8
|
+
import test from 'assert';
|
|
6
9
|
|
|
7
10
|
module.exports = MongoDBConnector;
|
|
8
11
|
|
package/lib/model.js
CHANGED
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
// should use promise objects to allow for method chaining
|
|
4
4
|
// eventful. emits ready event passing itself
|
|
5
5
|
// start with mongodb
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
import util from 'util';
|
|
7
|
+
import controller_base from './controller.js';
|
|
8
|
+
// var controller_base = require('./controller.js');
|
|
9
|
+
// var util = require('util');
|
|
8
10
|
|
|
9
11
|
/** TODO: what persistence methods does a model need?
|
|
10
12
|
* save/post => saves record to db
|
|
@@ -34,7 +36,6 @@ var util = require('util');
|
|
|
34
36
|
|
|
35
37
|
// init references to model base objects for use by controllers
|
|
36
38
|
// and models
|
|
37
|
-
var controller_base = require('./controller.js');
|
|
38
39
|
controller_base.prototype.models = {};
|
|
39
40
|
Model.prototype.models = {};
|
|
40
41
|
|
|
@@ -47,7 +48,7 @@ var NAME_REQUIRED_ERROR = function() {
|
|
|
47
48
|
);
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
function Model(){
|
|
51
|
+
export default function Model(){
|
|
51
52
|
};
|
|
52
53
|
|
|
53
54
|
Model.extend = function(constructor) {
|
package/lib/model_v2.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
let dbConnector = null;
|
|
2
2
|
|
|
3
|
-
class Model {
|
|
3
|
+
export default class Model {
|
|
4
4
|
static setConnector(connector) {
|
|
5
5
|
if (!dbConnector) dbConnector = connector;
|
|
6
6
|
}
|
|
@@ -9,5 +9,3 @@ class Model {
|
|
|
9
9
|
return dbConnector.generateModelSuperclass(modelName, connectorOptions);
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
module.exports = Model;
|
package/lib/mongodb_connector.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// TODO: multiple async requests here... need to
|
|
2
2
|
// consider how this will be used by the models
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
3
|
+
import {EventEmitter} from 'node:events';
|
|
4
|
+
// var EventEmitter = require('events').EventEmitter;
|
|
5
|
+
// const MongoClient = require('mongodb').MongoClient;
|
|
6
|
+
import { MongoClient } from 'mongodb';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
export default MongoDBConnector;
|
|
8
9
|
|
|
9
10
|
// TODO: need to deal with clustered databases...
|
|
10
11
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
const mongoose = require('mongoose');
|
|
1
|
+
// const mongoose = require('mongoose');
|
|
2
|
+
import mongoose from 'mongoose';
|
|
2
3
|
|
|
3
4
|
class MongooseDbConnector {
|
|
4
5
|
async connect(options) {
|
|
@@ -23,7 +24,7 @@ class MongooseDbConnector {
|
|
|
23
24
|
return this.connection.model(name, options.schema);
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
+
export default MongooseDbConnector;
|
|
27
28
|
/*
|
|
28
29
|
module.exports.connect = function(options) {
|
|
29
30
|
if (options.uri) return mongoose.createConnection(options.uri, mongooseOptions);
|
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
// const mongoose = require('mongoose');
|
|
2
|
-
const {MongoMemoryServer} = require('mongodb-memory-server');
|
|
2
|
+
// const {MongoMemoryServer} = require('mongodb-memory-server');
|
|
3
|
+
import { MongoMemoryServer } from 'mongodb-memory-server';
|
|
4
|
+
import MongooseDbConnector from './mongoose_connector.js';
|
|
5
|
+
// const MongooseDbConnector = require('./mongoose_connector');
|
|
3
6
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class MongooseMemoryConnector extends MongooseDbConnector {
|
|
7
|
+
export default class MongooseMemoryConnector extends MongooseDbConnector {
|
|
7
8
|
|
|
8
9
|
async connect() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
try {
|
|
11
|
+
const mongod = await MongoMemoryServer.create();
|
|
12
|
+
const uri = mongod.getUri();
|
|
13
|
+
console.error("The URI", uri);
|
|
14
|
+
const dbConfig = {uri: uri};
|
|
15
|
+
return super.connect(dbConfig);
|
|
16
|
+
} catch (e) {
|
|
17
|
+
console.error("Could not connect to MongoMemoryServer");
|
|
18
|
+
console.error(e);
|
|
19
|
+
}
|
|
14
20
|
}
|
|
15
|
-
}
|
|
16
|
-
module.exports = MongooseMemoryConnector;
|
|
21
|
+
}
|
package/lib/nails.js
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
// The file which configures the nails application
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const EventEmitter = require('events').EventEmitter;
|
|
2
|
+
import http from 'node:http';
|
|
3
|
+
import https from 'node:https';
|
|
4
|
+
import URL from 'node:url';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import { EventEmitter } from 'node:events';
|
|
9
8
|
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
9
|
+
// const http = require('http');
|
|
10
|
+
// const https = require('https');
|
|
11
|
+
// const URL = require('url');
|
|
12
|
+
// const path = require('path');
|
|
13
|
+
// const fs = require('fs');
|
|
14
|
+
// const EventEmitter = require('events').EventEmitter;
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
|
|
17
|
+
import Controller from './controller.js';
|
|
18
|
+
import Model from './model.js';
|
|
19
|
+
import ModelV2 from './model_v2.js';
|
|
20
|
+
import Router from './router.js';
|
|
21
|
+
|
|
22
|
+
import express_app from './application.js';
|
|
16
23
|
|
|
17
24
|
const models = {};
|
|
18
25
|
|
|
@@ -22,11 +29,12 @@ application.config = {};
|
|
|
22
29
|
|
|
23
30
|
// TODO: this should return a function (the configure function).
|
|
24
31
|
// Calling the function should return { startServer: startServer }.
|
|
25
|
-
|
|
32
|
+
// export defulat nails;
|
|
26
33
|
|
|
27
|
-
function nails(app_config) {
|
|
34
|
+
export default async function nails(app_config) {
|
|
28
35
|
nails.config = app_config.config;
|
|
29
36
|
application._onceConfigured = configure(app_config);
|
|
37
|
+
await application._onceConfigured;
|
|
30
38
|
return {startServer: startServer};
|
|
31
39
|
}
|
|
32
40
|
|
|
@@ -57,10 +65,13 @@ async function configure( app_config ) {
|
|
|
57
65
|
|
|
58
66
|
// set up router and controllers
|
|
59
67
|
express_app.set("public_root", app_config.config.PUBLIC_ROOT);
|
|
68
|
+
console.log("Initializing Router...");
|
|
60
69
|
application.router = new Router( app_config.routes || [] );
|
|
70
|
+
console.log("Application Router initialized");
|
|
61
71
|
|
|
62
72
|
// init models
|
|
63
|
-
|
|
73
|
+
console.log("Initializing DB connection...");
|
|
74
|
+
var DBConnector = await get_dbconnector(app_config.db.connector);
|
|
64
75
|
|
|
65
76
|
// TODO: deprecate the old Model style
|
|
66
77
|
if (app_config.config.MODELS_ROOT) {
|
|
@@ -68,15 +79,19 @@ async function configure( app_config ) {
|
|
|
68
79
|
init_models(app_config.config.MODELS_ROOT);
|
|
69
80
|
}
|
|
70
81
|
// TODO: make this Model style mandatory
|
|
82
|
+
console.log("Connecting to DB...");
|
|
71
83
|
if (DBConnector.connect && DBConnector.generateModelSuperclass) {
|
|
84
|
+
console.log("Generating model superclass...");
|
|
72
85
|
await DBConnector.connect(app_config.db);
|
|
73
86
|
ModelV2.setConnector(DBConnector);
|
|
74
87
|
} else {
|
|
88
|
+
console.log("Instantiating DBConnector...");
|
|
75
89
|
// Try to instantiate DBConnector
|
|
76
90
|
let dbConnector = new DBConnector();
|
|
77
91
|
await dbConnector.connect(app_config.db);
|
|
78
92
|
ModelV2.setConnector(dbConnector);
|
|
79
93
|
}
|
|
94
|
+
console.log("DB Connection complete");
|
|
80
95
|
|
|
81
96
|
// init Controllers
|
|
82
97
|
Controller.setRouter(application.router);
|
|
@@ -88,7 +103,7 @@ async function configure( app_config ) {
|
|
|
88
103
|
function startServer(config) {
|
|
89
104
|
// Log the config.
|
|
90
105
|
console.log(config);
|
|
91
|
-
//await application._onceConfigured;
|
|
106
|
+
// await application._onceConfigured;
|
|
92
107
|
console.log("CONFIGURATION COMPLETE");
|
|
93
108
|
// TODO: Use logging middleware.
|
|
94
109
|
application._onceConfigured.then(() => {
|
|
@@ -155,14 +170,16 @@ async function init_app_lib(superclass, abs_path) {
|
|
|
155
170
|
// require the module with the same name,
|
|
156
171
|
// try grabbing connector from lib
|
|
157
172
|
// (default connectors)
|
|
158
|
-
function get_dbconnector(connector_name) {
|
|
173
|
+
async function get_dbconnector(connector_name) {
|
|
174
|
+
console.log("Getting DBConnector:", connector_name);
|
|
159
175
|
var DBConnector;
|
|
160
176
|
//TODO: put mongodbconnector in its own module
|
|
161
177
|
try {
|
|
162
|
-
DBConnector =
|
|
178
|
+
DBConnector = (await import(connector_name)).default;
|
|
163
179
|
} catch(e) {
|
|
164
|
-
DBConnector =
|
|
180
|
+
DBConnector = (await import('./'+connector_name)).default;
|
|
165
181
|
}
|
|
182
|
+
console.log("Got DBConnector:", DBConnector.name);
|
|
166
183
|
return DBConnector;
|
|
167
184
|
}
|
|
168
185
|
|
package/lib/router.js
CHANGED
|
@@ -2,14 +2,25 @@
|
|
|
2
2
|
// server-side logic based on the matching route in the Routing Table
|
|
3
3
|
// ( See example/config/routes.js or config/routes.js for a description of the routes )
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
import {EventEmitter} from 'node:events';
|
|
6
|
+
// var EventEmitter = require('events').EventEmitter;
|
|
7
|
+
import URL from 'node:url';
|
|
8
|
+
// var URL = require('url');
|
|
9
|
+
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import querystring from 'node:querystring';
|
|
12
|
+
import express from 'express';
|
|
13
|
+
import expressWs from 'express-ws';
|
|
14
|
+
import app from './application.js'
|
|
15
|
+
// TODO use modular js only
|
|
16
|
+
import {_extend} from 'util';
|
|
17
|
+
|
|
18
|
+
// var path = require('path');
|
|
19
|
+
// var querystring = require('querystring');
|
|
20
|
+
// var expressWs = require('express-ws');
|
|
21
|
+
// var app = require('./application.js');
|
|
22
|
+
// //var nails = require('./nails.js');
|
|
23
|
+
// var _extend = require('util')._extend;
|
|
13
24
|
|
|
14
25
|
/**
|
|
15
26
|
* Creates a Router from an Array of route definitions
|
|
@@ -39,10 +50,15 @@ class Router extends EventEmitter {
|
|
|
39
50
|
if (Router.webSocketsEnabled) return;
|
|
40
51
|
Router.webSocketsEnabled = true;
|
|
41
52
|
Router.expressWs = expressWs(this.application);
|
|
53
|
+
expressWs(this.express_router);
|
|
54
|
+
// console.log("WS is still:", this.express_router.ws);
|
|
42
55
|
}
|
|
43
|
-
constructor(routes
|
|
56
|
+
constructor(routes) {
|
|
44
57
|
super();
|
|
45
|
-
this.application =
|
|
58
|
+
this.application = app;
|
|
59
|
+
// this.express_router = express.Router();
|
|
60
|
+
// console.log("the router is:", this.express_router);
|
|
61
|
+
// console.log("the ws is:", this.express_router.ws);
|
|
46
62
|
this.express_router = app.Router();
|
|
47
63
|
this.addRoutes(routes);
|
|
48
64
|
}
|
|
@@ -56,14 +72,13 @@ class Router extends EventEmitter {
|
|
|
56
72
|
var method = route[0].toLowerCase();
|
|
57
73
|
var path_matcher = route[1];
|
|
58
74
|
var consequences = route[2];
|
|
59
|
-
var is_public = consequences && consequences.public;
|
|
60
75
|
console.log("setting route for", method, path_matcher, consequences);
|
|
61
|
-
if (method.match(/ws/i)) {
|
|
76
|
+
if (method.match(/ws/i)) { // For some reason this hangs
|
|
62
77
|
this.enableWebSockets();
|
|
63
78
|
this.express_router.ws(
|
|
64
79
|
path_matcher,
|
|
65
80
|
this.get_websocket_handler(consequences));
|
|
66
|
-
} else if (consequences && consequences.public)
|
|
81
|
+
} else if (consequences && consequences.public) // Is a request for public asset
|
|
67
82
|
this.express_router.use(path_matcher,
|
|
68
83
|
this.application.static(this.application.get('public_root')));
|
|
69
84
|
else this.express_router[method](path_matcher,
|
|
@@ -184,4 +199,4 @@ class Router extends EventEmitter {
|
|
|
184
199
|
}
|
|
185
200
|
}
|
|
186
201
|
|
|
187
|
-
|
|
202
|
+
export default Router;
|
package/lib/sqlite3_connector.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
// TODO: multiple async requests here... need to
|
|
2
2
|
// consider how this will be used by the models
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import { EventEmitter } from 'events';
|
|
4
|
+
import DBClient from 'node:sqlite';
|
|
5
|
+
// var EventEmitter = require('events').EventEmitter;
|
|
6
|
+
// const DBClient = require('sqlite3');
|
|
7
|
+
import test from 'node:assert';
|
|
8
|
+
// const test = require('assert');
|
|
6
9
|
|
|
7
10
|
module.exports = SQLite3Connector;
|
|
8
11
|
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nails-boilerplate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "A node.js webserver scaffold",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "index.js",
|
|
6
7
|
"bin": {
|
|
7
8
|
"nails": "./bin/lib/nails.js"
|
|
8
9
|
},
|
|
9
10
|
"scripts": {
|
|
11
|
+
"copyreadme": "mammoth README.md templates/client/README.html",
|
|
10
12
|
"test": "mocha --exit spec",
|
|
11
13
|
"debug": "mocha --exit debug spec"
|
|
12
14
|
},
|
|
@@ -25,10 +27,9 @@
|
|
|
25
27
|
"dependencies": {
|
|
26
28
|
"@babel/core": "*",
|
|
27
29
|
"@babel/preset-react": "*",
|
|
28
|
-
"body-parser": "^
|
|
30
|
+
"body-parser": "^2.2.0",
|
|
29
31
|
"ejs": "*",
|
|
30
32
|
"express": "*",
|
|
31
|
-
"express-react-views": "*",
|
|
32
33
|
"express-ws": "*",
|
|
33
34
|
"mime": "*",
|
|
34
35
|
"mongodb": "^4.17.2",
|
|
@@ -36,6 +37,7 @@
|
|
|
36
37
|
"mongoose": "^6.13.0",
|
|
37
38
|
"react": "*",
|
|
38
39
|
"react-dom": "^16.13.1",
|
|
40
|
+
"showdown": "^2.1.0",
|
|
39
41
|
"wrench": "*"
|
|
40
42
|
},
|
|
41
43
|
"devDependencies": {
|
package/spec/controller.spec.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import Controller from '../lib/controller.js';
|
|
2
|
+
import assert from 'assert';
|
|
3
|
+
import sinon from 'sinon';
|
|
4
|
+
import {EventEmitter} from 'node:events';
|
|
5
|
+
|
|
5
6
|
function TestController() {
|
|
6
7
|
this.testAction = function () {};
|
|
7
8
|
};
|
|
@@ -24,12 +25,12 @@ describe('Controller', function() {
|
|
|
24
25
|
describe('Controller.constructor', function() {
|
|
25
26
|
it('should set the appropriate listener on the router',
|
|
26
27
|
function() {
|
|
27
|
-
mockRouter = new EventEmitter();
|
|
28
|
-
mockParams = {_controller: "test"};
|
|
29
|
-
mockRequest = {};
|
|
30
|
-
mockResponse = {headersSent: true};
|
|
28
|
+
let mockRouter = new EventEmitter();
|
|
29
|
+
let mockParams = {_controller: "test"};
|
|
30
|
+
let mockRequest = {};
|
|
31
|
+
let mockResponse = {headersSent: true};
|
|
31
32
|
Controller.setRouter(mockRouter);
|
|
32
|
-
testController = new TestEs6Controller();
|
|
33
|
+
let testController = new TestEs6Controller();
|
|
33
34
|
sinon.spy(testController, "testEs6Action");
|
|
34
35
|
|
|
35
36
|
mockRouter.emit(
|
|
@@ -42,7 +43,7 @@ describe('Controller', function() {
|
|
|
42
43
|
describe('Controller.extend', function() {
|
|
43
44
|
it('should error if an anonymous function is passed', function() {
|
|
44
45
|
try {
|
|
45
|
-
testController = Controller.extend(function(){});
|
|
46
|
+
let testController = Controller.extend(function(){});
|
|
46
47
|
assert(false); // Fail if we get here.
|
|
47
48
|
} catch(e) {
|
|
48
49
|
}
|
|
@@ -50,12 +51,12 @@ describe('Controller', function() {
|
|
|
50
51
|
|
|
51
52
|
it('should set the appropriate listener on the router',
|
|
52
53
|
function() {
|
|
53
|
-
mockRouter = new EventEmitter();
|
|
54
|
-
mockParams = {_controller: "test"};
|
|
55
|
-
mockRequest = {};
|
|
56
|
-
mockResponse = {headersSent: true};
|
|
54
|
+
let mockRouter = new EventEmitter();
|
|
55
|
+
let mockParams = {_controller: "test"};
|
|
56
|
+
let mockRequest = {};
|
|
57
|
+
let mockResponse = {headersSent: true};
|
|
57
58
|
Controller.setRouter(mockRouter);
|
|
58
|
-
testController = Controller.extend(TestController);
|
|
59
|
+
let testController = Controller.extend(TestController);
|
|
59
60
|
sinon.spy(testController, "testAction");
|
|
60
61
|
|
|
61
62
|
mockRouter.emit(
|
|
@@ -66,21 +67,21 @@ describe('Controller', function() {
|
|
|
66
67
|
});
|
|
67
68
|
it('should set itself as the prototype of the passed constructor method',
|
|
68
69
|
function() {
|
|
69
|
-
mockRouter = new EventEmitter();
|
|
70
|
+
let mockRouter = new EventEmitter();
|
|
70
71
|
Controller.setRouter(mockRouter);
|
|
71
|
-
testController = Controller.extend(TestController);
|
|
72
|
+
let testController = Controller.extend(TestController);
|
|
72
73
|
assert(testController instanceof Controller);
|
|
73
74
|
}
|
|
74
75
|
);
|
|
75
76
|
it('should return an initialized instance of the constructor', function() {
|
|
76
|
-
mockRouter = new EventEmitter();
|
|
77
|
+
let mockRouter = new EventEmitter();
|
|
77
78
|
Controller.setRouter(mockRouter);
|
|
78
|
-
testController = Controller.extend(TestController);
|
|
79
|
+
let testController = Controller.extend(TestController);
|
|
79
80
|
assert(testController instanceof TestController);
|
|
80
81
|
});
|
|
81
82
|
it('should raise an error if no router has been set', function() {
|
|
82
83
|
try {
|
|
83
|
-
testController = Controller.extend(TestController);
|
|
84
|
+
let testController = Controller.extend(TestController);
|
|
84
85
|
assert(false); // Fail if we get here.
|
|
85
86
|
} catch (expectedError) {
|
|
86
87
|
}
|
package/spec/model.spec.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import assert from 'assert';
|
|
2
|
+
import Model from '../lib/model.js';
|
|
3
|
+
import MongoDBConnectorUtil from './mongodb_connector.util.js';
|
|
4
4
|
|
|
5
5
|
var test_model = new Model();
|
|
6
6
|
var model_prot = Model.prototype;
|
package/spec/model_v2.spec.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import assert from 'assert';
|
|
2
|
+
import Model from '../lib/model_v2.js';
|
|
3
|
+
import MongooseConnectorUtil from './mongoose_connector.util.js';
|
|
4
4
|
|
|
5
5
|
const testSchema = {
|
|
6
6
|
name: String,
|