nails-boilerplate 0.13.0 → 0.14.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/lib/controller.js +6 -1
- package/lib/mongoose_connector.js +1 -1
- package/lib/mongoose_mem_connector.js +16 -0
- package/lib/nails.js +4 -3
- package/package.json +9 -4
- package/spec/model_v2.spec.js +0 -1
- package/spec/mongoose_connector.util.js +3 -16
- package/spec/services/integration/config/db.js +5 -4
- package/spec/services.integration.spec.js +3 -3
- package/templates/config/db.js +2 -1
package/lib/controller.js
CHANGED
|
@@ -117,7 +117,12 @@ class Controller {
|
|
|
117
117
|
// connection indefinitely.
|
|
118
118
|
actionResponse
|
|
119
119
|
.then(renderView)
|
|
120
|
-
.catch(error =>
|
|
120
|
+
.catch(error => {
|
|
121
|
+
// TODO: only do one of these
|
|
122
|
+
console.error(error);
|
|
123
|
+
console.log(error);
|
|
124
|
+
response.sendStatus(500, error);
|
|
125
|
+
});
|
|
121
126
|
} else renderView(actionResponse);
|
|
122
127
|
}
|
|
123
128
|
}
|
|
@@ -4,7 +4,6 @@ class MongooseDbConnector {
|
|
|
4
4
|
async connect(options) {
|
|
5
5
|
if (options.uri) {
|
|
6
6
|
this.connection = await mongoose.createConnection(options.uri/*, mongooseOptions*/).asPromise();
|
|
7
|
-
debugger;
|
|
8
7
|
} else {
|
|
9
8
|
var url = options.url || 'mongodb://127.0.0.1';
|
|
10
9
|
var port = options.port || '27017';
|
|
@@ -14,6 +13,7 @@ class MongooseDbConnector {
|
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
generateModelSuperclass(name, options) {
|
|
16
|
+
if (!this.connection) console.error("NO CONNECTION\n", this);
|
|
17
17
|
let schema = options.schema instanceof mongoose.Schema
|
|
18
18
|
? options.schema
|
|
19
19
|
: new mongoose.Schema(options.schema);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// const mongoose = require('mongoose');
|
|
2
|
+
const {MongoMemoryServer} = require('mongodb-memory-server');
|
|
3
|
+
|
|
4
|
+
const MongooseDbConnector = require('./mongoose_connector');
|
|
5
|
+
|
|
6
|
+
class MongooseMemoryConnector extends MongooseDbConnector {
|
|
7
|
+
|
|
8
|
+
async connect() {
|
|
9
|
+
const mongod = await MongoMemoryServer.create();
|
|
10
|
+
const uri = mongod.getUri();
|
|
11
|
+
console.error("The URI", uri);
|
|
12
|
+
const dbConfig = {uri: uri};
|
|
13
|
+
return super.connect(dbConfig);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
module.exports = MongooseMemoryConnector;
|
package/lib/nails.js
CHANGED
|
@@ -106,9 +106,10 @@ function startServer(config) {
|
|
|
106
106
|
|
|
107
107
|
let atLeastOneServerStarted = false;
|
|
108
108
|
let serverStartedCallback = () => {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
console.log("Started");
|
|
110
|
+
if (atLeastOneServerStarted) return;
|
|
111
|
+
nails.events.emit("ready", null);
|
|
112
|
+
atLeastOneServerStarted = true;
|
|
112
113
|
}
|
|
113
114
|
|
|
114
115
|
if (startHttp) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nails-boilerplate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "A node.js webserver scaffold",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -31,8 +31,9 @@
|
|
|
31
31
|
"express-react-views": "*",
|
|
32
32
|
"express-ws": "*",
|
|
33
33
|
"mime": "*",
|
|
34
|
-
"mongodb": "^4.
|
|
35
|
-
"
|
|
34
|
+
"mongodb": "^4.17.2",
|
|
35
|
+
"mongodb-memory-server": "^8.16.0",
|
|
36
|
+
"mongoose": "^6.13.0",
|
|
36
37
|
"react": "*",
|
|
37
38
|
"react-dom": "^16.13.1",
|
|
38
39
|
"wrench": "*"
|
|
@@ -41,10 +42,14 @@
|
|
|
41
42
|
"chai": "*",
|
|
42
43
|
"chai-http": "*",
|
|
43
44
|
"mocha": "^10.2.0",
|
|
44
|
-
"mongodb-memory-server": "^8.2.0",
|
|
45
45
|
"sinon": "*",
|
|
46
46
|
"ws": "*"
|
|
47
47
|
},
|
|
48
|
+
"config": {
|
|
49
|
+
"mongodbMemoryServer": {
|
|
50
|
+
"version": "latest"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
48
53
|
"author": "Stanton W. Jones",
|
|
49
54
|
"license": "MIT"
|
|
50
55
|
}
|
package/spec/model_v2.spec.js
CHANGED
|
@@ -1,31 +1,18 @@
|
|
|
1
|
-
const
|
|
2
|
-
const {MongoMemoryServer} = require('mongodb-memory-server');
|
|
1
|
+
const MongooseMemoryConnector = require('../lib/mongoose_mem_connector.js');
|
|
3
2
|
const mongoose = require('mongoose');
|
|
4
3
|
|
|
5
|
-
let promisedMongod = null;
|
|
6
|
-
|
|
7
4
|
class MongooseConnectorUtil {
|
|
8
5
|
constructor() {
|
|
9
6
|
this.mongoose = mongoose;
|
|
10
|
-
promisedMongod = MongoMemoryServer.create();
|
|
11
7
|
}
|
|
12
8
|
|
|
13
9
|
async getTestConnector() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const port = this.mongod.instanceInfo.port;
|
|
17
|
-
const dbPath = this.mongod.instanceInfo.dbPath;
|
|
18
|
-
const dbName = this.mongod.instanceInfo.dbName;
|
|
19
|
-
const dbConfig = {uri: uri};
|
|
20
|
-
//{uri: uri, port: port, database: dbName, dbPath: dbPath};
|
|
21
|
-
const dbConnector = new MongooseConnector();
|
|
22
|
-
this.connection = await dbConnector.connect(dbConfig);
|
|
10
|
+
const dbConnector = new MongooseMemoryConnector();
|
|
11
|
+
this.connection = await dbConnector.connect();
|
|
23
12
|
debugger;
|
|
24
13
|
return dbConnector;
|
|
25
14
|
}
|
|
26
15
|
async cleanup() {
|
|
27
|
-
//await this.mongod.stop();
|
|
28
|
-
//await this.connection.close();
|
|
29
16
|
debugger;
|
|
30
17
|
}
|
|
31
18
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
//connector: 'sqlite3_connector.js',
|
|
3
|
-
connector: 'mongoose_connector.js',
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
// connector: 'sqlite3_connector.js',
|
|
3
|
+
// connector: 'mongoose_connector.js',
|
|
4
|
+
connector: 'mongoose_mem_connector.js',
|
|
5
|
+
// url: 'mongodb://localhost',
|
|
6
|
+
// port: 4444,
|
|
6
7
|
|
|
7
8
|
dbName: 'development',
|
|
8
9
|
|
|
@@ -15,15 +15,15 @@ chai.should();
|
|
|
15
15
|
|
|
16
16
|
describe("Integration", function() {
|
|
17
17
|
before(function(done) {
|
|
18
|
-
MongoMemoryServer.create({instance: service_config.db}).then((mongodb) => {
|
|
19
|
-
|
|
18
|
+
// MongoMemoryServer.create({instance: service_config.db}).then((mongodb) => {
|
|
19
|
+
// mongod = mongodb;
|
|
20
20
|
var nails = require('./services/integration/server.js');
|
|
21
21
|
express_app = nails.application;
|
|
22
22
|
nails.events.on("ready", () => {
|
|
23
23
|
console.log("ready was emitted!");
|
|
24
24
|
done();
|
|
25
25
|
});
|
|
26
|
-
});
|
|
26
|
+
// });
|
|
27
27
|
});
|
|
28
28
|
describe("GET /", function() {
|
|
29
29
|
it('should return the expected JSON from index', function(done) {
|
package/templates/config/db.js
CHANGED