nails-boilerplate 0.9.0 → 0.10.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.
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
const mongoose = require('mongoose');
|
|
2
2
|
const mongooseOptions = {useNewUrlParser: true};
|
|
3
3
|
|
|
4
|
-
module.exports.connect = function(options) {
|
|
5
|
-
if (options.uri) mongoose.connect(options.uri, mongooseOptions);
|
|
4
|
+
module.exports.connect = async function(options) {
|
|
5
|
+
if (options.uri) return mongoose.connect(options.uri, mongooseOptions);
|
|
6
6
|
else {
|
|
7
7
|
var url = options.url || 'mongodb://localhost';
|
|
8
8
|
var port = options.port || '27017';
|
|
9
9
|
var database = options.database || 'nails';
|
|
10
|
-
mongoose.connect(`${url}:${port}/${database}`, mongooseOptions);
|
|
10
|
+
return mongoose.connect(`${url}:${port}/${database}`, mongooseOptions);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
|
package/lib/nails.js
CHANGED
|
@@ -24,7 +24,7 @@ module.exports = nails;
|
|
|
24
24
|
|
|
25
25
|
function nails(app_config) {
|
|
26
26
|
nails.config = app_config.config;
|
|
27
|
-
configure(app_config);
|
|
27
|
+
application._onceConfigured = configure(app_config);
|
|
28
28
|
return {startServer: startServer};
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -33,7 +33,7 @@ nails.Controller = Controller;
|
|
|
33
33
|
nails.Model = ModelV2;
|
|
34
34
|
nails.ModelDeprecated = Model;
|
|
35
35
|
|
|
36
|
-
function configure( app_config ) {
|
|
36
|
+
async function configure( app_config ) {
|
|
37
37
|
express_app.set('nails_config', application);
|
|
38
38
|
application.config = app_config.config;
|
|
39
39
|
// TODO: may not need mimes any more.
|
|
@@ -66,8 +66,8 @@ function configure( app_config ) {
|
|
|
66
66
|
}
|
|
67
67
|
// TODO: make this Model style mandatory
|
|
68
68
|
if (DBConnector.connect && DBConnector.generateModelSuperclass) {
|
|
69
|
-
DBConnector.connect(app_config.db);
|
|
70
|
-
ModelV2.setConnector(DBConnector);
|
|
69
|
+
await DBConnector.connect(app_config.db);
|
|
70
|
+
await ModelV2.setConnector(DBConnector);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
// init Controllers
|
|
@@ -80,15 +80,16 @@ function configure( app_config ) {
|
|
|
80
80
|
function startServer(config) {
|
|
81
81
|
// Log the config.
|
|
82
82
|
console.log(config);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
83
|
+
application._onceConfigured.then(() => {
|
|
84
|
+
// TODO: Use logging middleware.
|
|
85
|
+
|
|
86
|
+
// Use the router middleware.
|
|
87
|
+
express_app.use(application.router.express_router);
|
|
88
|
+
var ip = application.config.IP || 'localhost';
|
|
89
|
+
var port = application.config.PORT || 3000;
|
|
90
|
+
console.log("starting nails. listening to ", ip + ':' + port);
|
|
91
|
+
express_app.listen(port, ip);
|
|
92
|
+
});
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
// TODO: create an initializer lib file.
|
|
@@ -98,12 +99,12 @@ function init_controllers(controller_lib) {
|
|
|
98
99
|
function init_models(model_lib) {
|
|
99
100
|
init_app_lib(Model, model_lib);
|
|
100
101
|
}
|
|
101
|
-
function init_app_lib(superclass, abs_path) {
|
|
102
|
+
async function init_app_lib(superclass, abs_path) {
|
|
102
103
|
console.log('attempting to import:', abs_path);
|
|
103
104
|
if (!fs.existsSync(abs_path))
|
|
104
105
|
return console.log('Cannot initialize. Path not found.', abs_path);
|
|
105
106
|
if (fs.statSync(abs_path).isFile()) {
|
|
106
|
-
let subclass =
|
|
107
|
+
let subclass = (await import(abs_path)).default;
|
|
107
108
|
// Constructor function was provided
|
|
108
109
|
if (!superclass.isPrototypeOf(subclass))
|
|
109
110
|
return superclass.extend(subclass);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nails-boilerplate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.3",
|
|
4
4
|
"description": "A node.js webserver scaffold",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"express-react-views": "*",
|
|
31
31
|
"express-ws": "*",
|
|
32
32
|
"mime": "*",
|
|
33
|
-
"mongodb": "^3.
|
|
34
|
-
"mongoose": "
|
|
33
|
+
"mongodb": "^4.3.1",
|
|
34
|
+
"mongoose": "^6.1.8",
|
|
35
35
|
"react": "*",
|
|
36
36
|
"react-dom": "^16.13.1",
|
|
37
37
|
"wrench": "*"
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
const Controller =
|
|
3
|
+
require("../../../../../index.js").Controller;
|
|
4
|
+
*/
|
|
5
|
+
import nails from "../../../../../index.js";
|
|
6
|
+
export default class MjsController extends nails.Controller {
|
|
7
|
+
// DO NOT OVERRIDE CONSTRUCTOR
|
|
8
|
+
index(params, request, response) {
|
|
9
|
+
response.json({
|
|
10
|
+
classbased_index: true
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|