@misterzik/espressojs 3.1.16 → 3.1.17
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/.env +3 -7
- package/README.md +26 -18
- package/cli.js +2 -1
- package/config.json +16 -4
- package/index.js +41 -34
- package/package.json +12 -12
- package/routes/api/index.js +8 -8
- package/routes/db/index.js +1 -7
- package/routes/index.js +4 -4
- package/server/config/development.js +36 -0
- package/server/config/global.js +35 -0
- package/server/config/production.js +35 -0
- package/server/controllers/client/client.controller.js +27 -42
- package/server/index.js +4 -5
- package/server/utils/config.utils.js +23 -0
- package/server/utils/espresso-cli.js +55 -55
- package/server/utils/global.message.js +5 -28
- package/server/config/config.development.js +0 -40
- package/server/config/config.global.js +0 -38
- package/server/config/config.production.js +0 -38
package/.env
CHANGED
package/README.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
## EspressoJS / Espresso
|
|
4
4
|
|
|
5
|
-
###
|
|
5
|
+
### Introducing Espresso.JS, your ultimate Express configuration starting point and boilerplate. With its simplicity and lack of opinionation, EspressoJS offers plug-and-play configurations built on top of Express.
|
|
6
|
+
|
|
7
|
+
### Whether you're a beginner or an experienced developer, EspressoJS will have you up and running with an Express instance in a matter of seconds. Say goodbye to tedious setup and hello to streamlined development with EspressoJS.
|
|
6
8
|
|
|
7
9
|
## Getting Started
|
|
8
10
|
|
|
@@ -14,25 +16,32 @@
|
|
|
14
16
|
|
|
15
17
|
```
|
|
16
18
|
{
|
|
17
|
-
"instance": "
|
|
18
|
-
"hostname": "domain.com",
|
|
19
|
+
"instance": "development",
|
|
19
20
|
"port": 8080,
|
|
20
|
-
"
|
|
21
|
-
"
|
|
21
|
+
"hostname": "",
|
|
22
|
+
"mongoDB": {
|
|
23
|
+
"enabled": false,
|
|
24
|
+
"uri": "",
|
|
25
|
+
"instance": "database"
|
|
26
|
+
},
|
|
27
|
+
"api": {
|
|
28
|
+
"enabled": false,
|
|
29
|
+
"uri": "https://swapi.dev/api/people/",
|
|
30
|
+
"url": "",
|
|
31
|
+
"method": "GET",
|
|
32
|
+
"headers": {
|
|
33
|
+
"Content-Type": "application/json"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
22
36
|
}
|
|
23
37
|
```
|
|
24
38
|
|
|
25
39
|
- Create `.env` if you don't want to use config. A mix is possible.
|
|
26
40
|
|
|
27
41
|
```
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
API_URI_ON=FALSE
|
|
32
|
-
API_URI=""
|
|
33
|
-
API_METHOD="GET"
|
|
34
|
-
API_OBJ_URL=""
|
|
35
|
-
PORT=8080
|
|
42
|
+
MONGO_USER=USER
|
|
43
|
+
MONGO_TOKEN=PASSWORD
|
|
44
|
+
API_TOKEN=APITOKEN
|
|
36
45
|
```
|
|
37
46
|
|
|
38
47
|
- Create `espresso.js` and add the following requirements to call the packages.
|
|
@@ -52,14 +61,13 @@
|
|
|
52
61
|
node cli run
|
|
53
62
|
```
|
|
54
63
|
|
|
55
|
-
|
|
56
64
|
### Structured Files
|
|
57
65
|
|
|
58
|
-
|
|
66
|
+
Pre-made Configurations:
|
|
59
67
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
68
|
+
- `server/config/config.global.js`
|
|
69
|
+
- `server/config/config.production.js`
|
|
70
|
+
- `server/config/config.development.js`
|
|
63
71
|
|
|
64
72
|
### Commands
|
|
65
73
|
|
package/cli.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
require("./server/utils/espresso-cli");
|
|
1
|
+
const cli = require("./server/utils/espresso-cli");
|
|
2
|
+
module.exports = cli;
|
package/config.json
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
{
|
|
2
|
-
"instance": "
|
|
2
|
+
"instance": "development",
|
|
3
3
|
"port": 8080,
|
|
4
4
|
"hostname": "",
|
|
5
|
-
"mongoDB":
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"mongoDB": {
|
|
6
|
+
"enabled": false,
|
|
7
|
+
"port": null,
|
|
8
|
+
"uri": "",
|
|
9
|
+
"instance": "database"
|
|
10
|
+
},
|
|
11
|
+
"api": {
|
|
12
|
+
"enabled": false,
|
|
13
|
+
"uri": "https://swapi.dev/api/people/",
|
|
14
|
+
"url": "",
|
|
15
|
+
"method": "GET",
|
|
16
|
+
"headers": {
|
|
17
|
+
"Content-Type": "application/json"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
8
20
|
}
|
package/index.js
CHANGED
|
@@ -4,49 +4,47 @@
|
|
|
4
4
|
* _| _| _| _| _| _| _|
|
|
5
5
|
* _| _| _| _| _| _|
|
|
6
6
|
* _| _| _| _|_|_|
|
|
7
|
-
* EspressoJS - EspressoJS / Espresso
|
|
7
|
+
* EspressoJS - EspressoJS / Espresso
|
|
8
8
|
* Express Plug & Play Server
|
|
9
9
|
* -----------------
|
|
10
10
|
* @param {*} app - EspressoJS by Vimedev.com Labs
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
|
-
const fs = require("fs");
|
|
14
12
|
require("dotenv").config();
|
|
15
13
|
const express = require("express");
|
|
16
14
|
const app = express();
|
|
17
15
|
const cfg = require("./server");
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
configData = JSON.parse(configJSON);
|
|
21
|
-
|
|
22
|
-
const Path = require("path"),
|
|
23
|
-
Cors = require("cors"),
|
|
24
|
-
Compression = require("compression"),
|
|
25
|
-
Favicon = require("serve-favicon"),
|
|
26
|
-
Static = require("serve-static"),
|
|
27
|
-
Port = configData.port || process.env.PORT || cfg.port,
|
|
28
|
-
Routes = require("./routes/index");
|
|
16
|
+
const { readConfigFile } = require("./server/utils/config.utils");
|
|
17
|
+
const configData = readConfigFile();
|
|
29
18
|
|
|
19
|
+
const Path = require("path");
|
|
20
|
+
const Cors = require("cors");
|
|
21
|
+
const Compression = require("compression");
|
|
22
|
+
const Favicon = require("serve-favicon");
|
|
23
|
+
const Static = require("serve-static");
|
|
30
24
|
const mongoose = require("mongoose");
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
const Routes = require("./routes/index");
|
|
26
|
+
|
|
27
|
+
const Port = configData.port || cfg.port;
|
|
28
|
+
const mongoConfig = configData.mongo;
|
|
29
|
+
|
|
30
|
+
if (configData.mongo_isEnabled) {
|
|
31
|
+
const {
|
|
32
|
+
uri: mongoUri = configData.mongo.uri || "",
|
|
33
|
+
port: mongoPort = configData.mongo.port || "",
|
|
34
|
+
db: mongoDb = configData.mongo.db || "",
|
|
35
|
+
} = mongoConfig;
|
|
36
|
+
const hasPort = mongoPort ? `:${mongoPort}/` : "/";
|
|
37
|
+
const url = `mongodb+srv://${
|
|
38
|
+
process.env.MONGO_USER +
|
|
39
|
+
":" +
|
|
40
|
+
process.env.MONGO_TOKEN +
|
|
41
|
+
"@" +
|
|
42
|
+
mongoUri
|
|
43
|
+
+
|
|
44
|
+
hasPort +
|
|
45
|
+
mongoDb
|
|
46
|
+
}`;
|
|
36
47
|
|
|
37
|
-
if (cfg.mongo_isEnabled == true) {
|
|
38
|
-
let hasPort, hasUri;
|
|
39
|
-
if (cfg.mongo.port == "") {
|
|
40
|
-
hasPort = "/";
|
|
41
|
-
} else {
|
|
42
|
-
hasPort = ":" + cfg.mongo.port + "/";
|
|
43
|
-
}
|
|
44
|
-
if (cfg.mongo.uri == "") {
|
|
45
|
-
hasUri = process.env.MONGO_URI;
|
|
46
|
-
} else {
|
|
47
|
-
hasUri = cfg.mongo.uri;
|
|
48
|
-
}
|
|
49
|
-
const url = `mongodb+srv://${hasUri + hasPort + cfg.mongo.db}`;
|
|
50
48
|
mongoose.Promise = global.Promise;
|
|
51
49
|
mongoose
|
|
52
50
|
.connect(url, {
|
|
@@ -54,10 +52,16 @@ if (cfg.mongo_isEnabled == true) {
|
|
|
54
52
|
useNewUrlParser: true,
|
|
55
53
|
promiseLibrary: require("bluebird"),
|
|
56
54
|
})
|
|
57
|
-
.then(() => console.log(":: DB Connection
|
|
55
|
+
.then(() => console.log(":: DB Connection successful ::"))
|
|
58
56
|
.catch((err) => console.error(err));
|
|
59
57
|
}
|
|
60
58
|
|
|
59
|
+
const setCustomCacheControl = (res, path) => {
|
|
60
|
+
if (Static.mime.lookup(path) === "text/html") {
|
|
61
|
+
res.setHeader("Cache-Control", "public, max-age=0");
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
61
65
|
app.use(Compression());
|
|
62
66
|
app.use(Cors());
|
|
63
67
|
app.use(express.urlencoded({ extended: false }));
|
|
@@ -73,5 +77,8 @@ app.use(
|
|
|
73
77
|
);
|
|
74
78
|
|
|
75
79
|
Routes(app);
|
|
76
|
-
app.listen(Port)
|
|
80
|
+
app.listen(Port, () => {
|
|
81
|
+
console.log(`Server is running on port ${Port}`);
|
|
82
|
+
});
|
|
83
|
+
|
|
77
84
|
module.exports = app;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@misterzik/espressojs",
|
|
3
|
-
"version": "3.1.
|
|
4
|
-
"description": "EspressoJS
|
|
3
|
+
"version": "3.1.17",
|
|
4
|
+
"description": "EspressoJS Introducing Espresso.JS, your ultimate Express configuration starting point and boilerplate. With its simplicity and lack of opinionation, EspressoJS offers plug-and-play configurations built on top of Express.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\"",
|
|
@@ -36,24 +36,24 @@
|
|
|
36
36
|
},
|
|
37
37
|
"homepage": "https://github.com/misterzik/Espresso.js#readme",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"axios": "^
|
|
39
|
+
"axios": "^1.4.0",
|
|
40
40
|
"bluebird": "^3.7.2",
|
|
41
41
|
"cross-env": "^7.0.3",
|
|
42
|
-
"express": "^4.
|
|
43
|
-
"mongoose": "^
|
|
44
|
-
"dotenv": "^
|
|
42
|
+
"express": "^4.18.2",
|
|
43
|
+
"mongoose": "^7.3.0",
|
|
44
|
+
"dotenv": "^16.3.1",
|
|
45
45
|
"cors": "^2.8.5",
|
|
46
|
-
"finalhandler": "^1.
|
|
46
|
+
"finalhandler": "^1.2.0",
|
|
47
47
|
"compression": "^1.7.4",
|
|
48
|
-
"serve-static": "^1.
|
|
48
|
+
"serve-static": "^1.15.0",
|
|
49
49
|
"serve-favicon": "^2.5.0",
|
|
50
|
-
"yargs": "^17.2
|
|
50
|
+
"yargs": "^17.7.2"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"debug": "^4.
|
|
54
|
-
"@babel/core": "^7.
|
|
53
|
+
"debug": "^4.3.4",
|
|
54
|
+
"@babel/core": "^7.22.5",
|
|
55
55
|
"amd-define-factory-patcher-loader": "^1.0.0",
|
|
56
|
-
"babel-loader": "^
|
|
56
|
+
"babel-loader": "^9.1.2",
|
|
57
57
|
"babel-preset-env": "^1.7.0"
|
|
58
58
|
},
|
|
59
59
|
"engines": {
|
package/routes/api/index.js
CHANGED
|
@@ -14,7 +14,7 @@ const configuration = require("../../server");
|
|
|
14
14
|
|
|
15
15
|
const getAPI = (req, res) => {
|
|
16
16
|
axios
|
|
17
|
-
.get(configuration.
|
|
17
|
+
.get(configuration.api.uri, configuration.api.configs)
|
|
18
18
|
.then(function (response) {
|
|
19
19
|
if (response.status == 200) {
|
|
20
20
|
res.json(response.data);
|
|
@@ -27,11 +27,11 @@ const getAPI = (req, res) => {
|
|
|
27
27
|
|
|
28
28
|
const getItem = (req, res, params) => {
|
|
29
29
|
axios
|
|
30
|
-
.get(configuration.
|
|
30
|
+
.get(configuration.api.uri + "/" + params, configuration.api.configs)
|
|
31
31
|
.then(function (response) {
|
|
32
|
-
if (response.status
|
|
32
|
+
if (response.status === 200) {
|
|
33
33
|
res.json(response.data);
|
|
34
|
-
} else if (response.status
|
|
34
|
+
} else if (response.status === 400) {
|
|
35
35
|
res.json({ message: "400" });
|
|
36
36
|
}
|
|
37
37
|
})
|
|
@@ -41,13 +41,13 @@ const getItem = (req, res, params) => {
|
|
|
41
41
|
const getItemId = (req, res, params, paramsId) => {
|
|
42
42
|
axios
|
|
43
43
|
.get(
|
|
44
|
-
configuration.
|
|
45
|
-
configuration.
|
|
44
|
+
configuration.api.uri + params + "/" + paramsId + "/",
|
|
45
|
+
configuration.api.configs
|
|
46
46
|
)
|
|
47
47
|
.then(function (response) {
|
|
48
|
-
if (response.status
|
|
48
|
+
if (response.status === 200) {
|
|
49
49
|
res.json(response.data);
|
|
50
|
-
} else if (response.status
|
|
50
|
+
} else if (response.status === 400) {
|
|
51
51
|
res.json({ message: "400" });
|
|
52
52
|
}
|
|
53
53
|
})
|
package/routes/db/index.js
CHANGED
|
@@ -12,29 +12,23 @@
|
|
|
12
12
|
|
|
13
13
|
module.exports = (app) => {
|
|
14
14
|
const clientRouter = require("../../server/controllers/client/client.controller.js");
|
|
15
|
-
const
|
|
16
|
-
url = preFix;
|
|
17
|
-
|
|
15
|
+
const url = "/api/clients/";
|
|
18
16
|
/**
|
|
19
17
|
* Create
|
|
20
18
|
*/
|
|
21
19
|
app.post(url, clientRouter.create);
|
|
22
|
-
|
|
23
20
|
/**
|
|
24
21
|
* Get All
|
|
25
22
|
*/
|
|
26
23
|
app.get(url, clientRouter.findAll);
|
|
27
|
-
|
|
28
24
|
/**
|
|
29
25
|
* Retrieve a single Note with clientId
|
|
30
26
|
*/
|
|
31
27
|
app.get(url + ":clientId", clientRouter.findOne);
|
|
32
|
-
|
|
33
28
|
/**
|
|
34
29
|
* Update a Note with clientId
|
|
35
30
|
*/
|
|
36
31
|
app.put(url + ":clientId", clientRouter.update);
|
|
37
|
-
|
|
38
32
|
/**
|
|
39
33
|
* Delete a Note with clientId
|
|
40
34
|
*/
|
package/routes/index.js
CHANGED
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
module.exports = (app) => {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const Path = require("path");
|
|
14
|
+
const configuration = require("../server");
|
|
15
|
+
const api = require("./api");
|
|
16
16
|
app.get("/", function (res) {
|
|
17
17
|
res.sendFile("index.html", { root: Path.join("./public") });
|
|
18
18
|
});
|
|
19
|
-
if (configuration.
|
|
19
|
+
if (configuration.api_isEnabled === true) {
|
|
20
20
|
app.use("/api", api);
|
|
21
21
|
}
|
|
22
22
|
require("./db")(app);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* _| _| _| _| _|_|_|
|
|
3
|
+
* _| _| _|_| _|_| _| _|
|
|
4
|
+
* _| _| _| _| _| _| _|
|
|
5
|
+
* _| _| _| _| _| _|
|
|
6
|
+
* _| _| _| _|_|_|
|
|
7
|
+
* EspressoJS - EspressoJS / Espresso
|
|
8
|
+
* Dev Template
|
|
9
|
+
*/
|
|
10
|
+
require("dotenv").config();
|
|
11
|
+
const { readConfigFile } = require("../utils/config.utils");
|
|
12
|
+
const data = readConfigFile();
|
|
13
|
+
|
|
14
|
+
const config = {
|
|
15
|
+
env: data.instance || "development",
|
|
16
|
+
hostname: data.hostname || "dev.example.com",
|
|
17
|
+
port: data.port || "8080",
|
|
18
|
+
mongo_isEnabled:
|
|
19
|
+
data.mongoDB.enabled !== undefined ? data.mongoDB.enabled : true,
|
|
20
|
+
mongo: {
|
|
21
|
+
uri: data.mongoDB.uri || "localhost",
|
|
22
|
+
port: data.mongoDB.port || "27017",
|
|
23
|
+
db: data.mongoDB.instance || "myFirstDatabase",
|
|
24
|
+
},
|
|
25
|
+
api_isEnabled: data.api.enabled !== undefined ? data.api.enabled : true,
|
|
26
|
+
api: {
|
|
27
|
+
uri: data.api.uri || "https://swapi.dev/api/people/",
|
|
28
|
+
configs: {
|
|
29
|
+
method: data.api.method || "GET",
|
|
30
|
+
url: data.api.url || "",
|
|
31
|
+
headers: data.api.headers,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
module.exports = config;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* _| _| _| _| _|_|_|
|
|
3
|
+
* _| _| _|_| _|_| _| _|
|
|
4
|
+
* _| _| _| _| _| _| _|
|
|
5
|
+
* _| _| _| _| _| _|
|
|
6
|
+
* _| _| _| _|_|_|
|
|
7
|
+
* EspressoJS - EspressoJS / Espresso
|
|
8
|
+
* Global Template w/ API
|
|
9
|
+
*/
|
|
10
|
+
require("dotenv").config();
|
|
11
|
+
const { readConfigFile } = require("../utils/config.utils");
|
|
12
|
+
const data = readConfigFile();
|
|
13
|
+
|
|
14
|
+
const config = {
|
|
15
|
+
env: data.instance || "global",
|
|
16
|
+
hostname: data.hostname || "example.com",
|
|
17
|
+
port: data.port || "8080",
|
|
18
|
+
mongo_isEnabled:
|
|
19
|
+
data.mongoDB.enabled !== undefined ? data.mongoDB.enabled : false,
|
|
20
|
+
mongo: {
|
|
21
|
+
uri: data.mongoDB.uri || "localhost",
|
|
22
|
+
port: data.mongoDB.port || "27017",
|
|
23
|
+
db: data.mongoDB.instance || "myFirstDatabase",
|
|
24
|
+
},
|
|
25
|
+
api_isEnabled: data.api.enabled !== undefined ? data.api.enabled : false,
|
|
26
|
+
api: {
|
|
27
|
+
uri: data.api.uri || "https://swapi.dev/api/people/",
|
|
28
|
+
configs: {
|
|
29
|
+
method: data.api.method || "GET",
|
|
30
|
+
url: data.api.url || "",
|
|
31
|
+
headers: data.api.headers,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
module.exports = config;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* _| _| _| _| _|_|_|
|
|
3
|
+
* _| _| _|_| _|_| _| _|
|
|
4
|
+
* _| _| _| _| _| _| _|
|
|
5
|
+
* _| _| _| _| _| _|
|
|
6
|
+
* _| _| _| _|_|_|
|
|
7
|
+
* EspressoJS - EspressoJS / Espresso
|
|
8
|
+
* Production Template
|
|
9
|
+
*/
|
|
10
|
+
require("dotenv").config();
|
|
11
|
+
const { readConfigFile } = require("../utils/config.utils");
|
|
12
|
+
const data = readConfigFile();
|
|
13
|
+
|
|
14
|
+
const config = {
|
|
15
|
+
env: data.instance || "production",
|
|
16
|
+
hostname: data.hostname,
|
|
17
|
+
port: data.port || "80",
|
|
18
|
+
mongo_isEnabled:
|
|
19
|
+
data.mongoDB.enabled !== undefined ? data.mongoDB.enabled : false,
|
|
20
|
+
mongo: {
|
|
21
|
+
uri: data.mongoDB.uri || "localhost",
|
|
22
|
+
port: data.mongoDB.port || "27017",
|
|
23
|
+
db: data.mongoDB.instance || "myFirstDatabase",
|
|
24
|
+
},
|
|
25
|
+
api_isEnabled: data.api.enabled !== undefined ? data.api.enabled : false,
|
|
26
|
+
api: {
|
|
27
|
+
uri: data.api.uri || "https://swapi.dev/api/people/",
|
|
28
|
+
configs: {
|
|
29
|
+
method: data.api.method || "GET",
|
|
30
|
+
url: data.api.url || "",
|
|
31
|
+
headers: data.api.headers,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
module.exports = config;
|
|
@@ -4,17 +4,17 @@
|
|
|
4
4
|
* _| _| _| _| _| _| _|
|
|
5
5
|
* _| _| _| _| _| _|
|
|
6
6
|
* _| _| _| _|_|_|
|
|
7
|
-
* EspressoJS - EspressoJS / Espresso is your one-stop
|
|
7
|
+
* EspressoJS - EspressoJS / Espresso is your one-stop
|
|
8
8
|
* Express Configuration starting point
|
|
9
9
|
*/
|
|
10
|
+
|
|
10
11
|
const Client = require("../../models/client.model.js");
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
|
-
* Retrieve and return all
|
|
14
|
-
* @param {*} req - Request data
|
|
15
|
-
* @param {*} res - Response
|
|
14
|
+
* Retrieve and return all clients from the collection.
|
|
15
|
+
* @param {*} req - Request data
|
|
16
|
+
* @param {*} res - Response data
|
|
16
17
|
*/
|
|
17
|
-
|
|
18
18
|
exports.findAll = (req, res) => {
|
|
19
19
|
Client.find()
|
|
20
20
|
.then((clients) => {
|
|
@@ -22,38 +22,29 @@ exports.findAll = (req, res) => {
|
|
|
22
22
|
})
|
|
23
23
|
.catch((err) => {
|
|
24
24
|
res.status(500).send({
|
|
25
|
-
message:
|
|
26
|
-
err.message || "Error occurred while retrieving your collections.",
|
|
25
|
+
message: err.message || "Error occurred while retrieving clients.",
|
|
27
26
|
});
|
|
28
27
|
});
|
|
29
28
|
};
|
|
30
29
|
|
|
31
30
|
/**
|
|
32
|
-
* Create and
|
|
33
|
-
* @param {*} req
|
|
34
|
-
* @param {*} res
|
|
31
|
+
* Create and save a new client to the collection.
|
|
32
|
+
* @param {*} req - Request data
|
|
33
|
+
* @param {*} res - Response data
|
|
35
34
|
*/
|
|
36
|
-
|
|
37
35
|
exports.create = (req, res) => {
|
|
38
36
|
if (!req.body.email) {
|
|
39
37
|
return res.status(400).send({
|
|
40
|
-
message: "
|
|
38
|
+
message: "Email cannot be an empty field.",
|
|
41
39
|
});
|
|
42
40
|
}
|
|
43
41
|
|
|
44
|
-
/**
|
|
45
|
-
* Client Body to be created after
|
|
46
|
-
* Request byPass of cannot be null
|
|
47
|
-
*/
|
|
48
42
|
const client = new Client({
|
|
49
43
|
name: req.body.name || "John Doe",
|
|
50
44
|
email: req.body.email,
|
|
51
45
|
location: req.body.location,
|
|
52
46
|
});
|
|
53
47
|
|
|
54
|
-
/**
|
|
55
|
-
* Save Client in the document collection
|
|
56
|
-
*/
|
|
57
48
|
client
|
|
58
49
|
.save()
|
|
59
50
|
.then((data) => {
|
|
@@ -61,23 +52,22 @@ exports.create = (req, res) => {
|
|
|
61
52
|
})
|
|
62
53
|
.catch((err) => {
|
|
63
54
|
res.status(500).send({
|
|
64
|
-
message: err.message || "Error occurred while creating the
|
|
55
|
+
message: err.message || "Error occurred while creating the client.",
|
|
65
56
|
});
|
|
66
57
|
});
|
|
67
58
|
};
|
|
68
59
|
|
|
69
60
|
/**
|
|
70
|
-
* Find a single client
|
|
71
|
-
* @param {*} req
|
|
72
|
-
* @param {*} res
|
|
61
|
+
* Find a single client by clientId.
|
|
62
|
+
* @param {*} req - Request data
|
|
63
|
+
* @param {*} res - Response data
|
|
73
64
|
*/
|
|
74
65
|
exports.findOne = (req, res) => {
|
|
75
66
|
Client.findById(req.params.clientId)
|
|
76
67
|
.then((client) => {
|
|
77
68
|
if (!client) {
|
|
78
69
|
return res.status(404).send({
|
|
79
|
-
message:
|
|
80
|
-
"Client not found with the following id " + req.params.clientId,
|
|
70
|
+
message: "Client not found with id " + req.params.clientId,
|
|
81
71
|
});
|
|
82
72
|
}
|
|
83
73
|
res.send(client);
|
|
@@ -95,10 +85,9 @@ exports.findOne = (req, res) => {
|
|
|
95
85
|
};
|
|
96
86
|
|
|
97
87
|
/**
|
|
98
|
-
* Update a client
|
|
99
|
-
*
|
|
100
|
-
* @param {*}
|
|
101
|
-
* @param {*} res
|
|
88
|
+
* Update a client identified by clientId.
|
|
89
|
+
* @param {*} req - Request data
|
|
90
|
+
* @param {*} res - Response data
|
|
102
91
|
*/
|
|
103
92
|
exports.update = (req, res) => {
|
|
104
93
|
if (!req.body.email) {
|
|
@@ -107,10 +96,6 @@ exports.update = (req, res) => {
|
|
|
107
96
|
});
|
|
108
97
|
}
|
|
109
98
|
|
|
110
|
-
/**
|
|
111
|
-
* Find client and update it with the request body
|
|
112
|
-
* depending on _id
|
|
113
|
-
*/
|
|
114
99
|
Client.findByIdAndUpdate(
|
|
115
100
|
req.params.clientId,
|
|
116
101
|
{
|
|
@@ -120,13 +105,13 @@ exports.update = (req, res) => {
|
|
|
120
105
|
},
|
|
121
106
|
{ new: true }
|
|
122
107
|
)
|
|
123
|
-
.then((
|
|
124
|
-
if (!
|
|
108
|
+
.then((client) => {
|
|
109
|
+
if (!client) {
|
|
125
110
|
return res.status(404).send({
|
|
126
111
|
message: "Client not found with id " + req.params.clientId,
|
|
127
112
|
});
|
|
128
113
|
}
|
|
129
|
-
res.send(
|
|
114
|
+
res.send(client);
|
|
130
115
|
})
|
|
131
116
|
.catch((err) => {
|
|
132
117
|
if (err.kind === "ObjectId") {
|
|
@@ -141,14 +126,14 @@ exports.update = (req, res) => {
|
|
|
141
126
|
};
|
|
142
127
|
|
|
143
128
|
/**
|
|
144
|
-
* Delete a client
|
|
145
|
-
* @param {*} req
|
|
146
|
-
* @param {*} res
|
|
129
|
+
* Delete a client by clientId.
|
|
130
|
+
* @param {*} req - Request data
|
|
131
|
+
* @param {*} res - Response data
|
|
147
132
|
*/
|
|
148
133
|
exports.delete = (req, res) => {
|
|
149
134
|
Client.findByIdAndRemove(req.params.clientId)
|
|
150
|
-
.then((
|
|
151
|
-
if (!
|
|
135
|
+
.then((client) => {
|
|
136
|
+
if (!client) {
|
|
152
137
|
return res.status(404).send({
|
|
153
138
|
message: "Client not found with id " + req.params.clientId,
|
|
154
139
|
});
|
|
@@ -162,7 +147,7 @@ exports.delete = (req, res) => {
|
|
|
162
147
|
});
|
|
163
148
|
}
|
|
164
149
|
return res.status(500).send({
|
|
165
|
-
message: "Could not delete
|
|
150
|
+
message: "Could not delete client with id " + req.params.clientId,
|
|
166
151
|
});
|
|
167
152
|
});
|
|
168
153
|
};
|
package/server/index.js
CHANGED
|
@@ -6,10 +6,9 @@
|
|
|
6
6
|
* _| _| _| _|_|_|
|
|
7
7
|
* EspressoJS
|
|
8
8
|
*/
|
|
9
|
-
const fs = require("fs");
|
|
10
9
|
require("dotenv").config();
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const env = data.instance ||
|
|
14
|
-
const cfg = require("./config/
|
|
10
|
+
const { readConfigFile } = require("./utils/config.utils");
|
|
11
|
+
const data = readConfigFile();
|
|
12
|
+
const env = data.instance || "development";
|
|
13
|
+
const cfg = require("./config/" + env);
|
|
15
14
|
module.exports = cfg;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
|
|
3
|
+
function readConfigFile() {
|
|
4
|
+
const cfgBuffer = fs.readFileSync("./config.json");
|
|
5
|
+
const cfgBuJSON = cfgBuffer.toString();
|
|
6
|
+
return JSON.parse(cfgBuJSON);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function writeConfigFile(cfg) {
|
|
10
|
+
const instUpdate = JSON.stringify(cfg);
|
|
11
|
+
fs.writeFileSync("config.json", instUpdate);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const vmdLogo = `
|
|
15
|
+
( (
|
|
16
|
+
) )
|
|
17
|
+
........
|
|
18
|
+
| .VMD |]
|
|
19
|
+
| /
|
|
20
|
+
'----'/.ZI|<..
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
module.exports = { readConfigFile, writeConfigFile, vmdLogo };
|
|
@@ -6,56 +6,71 @@
|
|
|
6
6
|
* _| _| _| _|_|_|
|
|
7
7
|
* EspressoJS - CLI
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
const { exec } = require("child_process");
|
|
11
11
|
const { string, number } = require("yargs");
|
|
12
12
|
const yargs = require("yargs");
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const cfgB =
|
|
13
|
+
const { readConfigFile, writeConfigFile, vmdLogo } = require("./config.utils");
|
|
14
|
+
|
|
15
|
+
const cfgB = readConfigFile();
|
|
16
|
+
function showCommand() {
|
|
17
|
+
console.log(cfgB);
|
|
18
|
+
}
|
|
19
|
+
function runCommand() {
|
|
20
|
+
if (cfgB !== undefined) {
|
|
21
|
+
const cmd_ct = vmdLogo;
|
|
22
|
+
console.warn(`${cmd_ct}`);
|
|
23
|
+
console.warn(
|
|
24
|
+
`Espresso CLI
|
|
25
|
+
--------------
|
|
26
|
+
Warming Up Configs..
|
|
27
|
+
Running ....
|
|
28
|
+
|
|
29
|
+
Instance Config:
|
|
30
|
+
Configuration: ${cfgB.instance}
|
|
31
|
+
Endpoint: localhost:${cfgB.port}
|
|
32
|
+
JSON:`,
|
|
33
|
+
cfgB,
|
|
34
|
+
`\n\nTo stop process press CTRL+C`
|
|
35
|
+
);
|
|
36
|
+
exec(
|
|
37
|
+
`node ./node_modules/cross-env/src/bin/cross-env NODE_ENV=${cfgB.instance} PORT=${cfgB.port} node index.js`,
|
|
38
|
+
(error, stdout, stderr) => {
|
|
39
|
+
if (error) {
|
|
40
|
+
console.log(`error: ${error.message}`);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (stderr) {
|
|
44
|
+
console.log(`stderr: ${stderr}`);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
console.log(`stdout: ${stdout}`);
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function envCommand(argv) {
|
|
53
|
+
if (argv.instance !== undefined) {
|
|
54
|
+
cfgB.instance = argv.instance;
|
|
55
|
+
}
|
|
56
|
+
if (cfgB.port !== argv.port) {
|
|
57
|
+
cfgB.port = argv.port;
|
|
58
|
+
console.warn("New config saved...");
|
|
59
|
+
} else {
|
|
60
|
+
console.warn("Config already saved...");
|
|
61
|
+
}
|
|
62
|
+
writeConfigFile(cfgB)
|
|
63
|
+
}
|
|
16
64
|
|
|
17
65
|
yargs.command({
|
|
18
66
|
command: "show",
|
|
19
67
|
describe: "Show pre-compiled Instance",
|
|
20
|
-
handler:
|
|
21
|
-
console.log(cfgB);
|
|
22
|
-
},
|
|
68
|
+
handler: showCommand,
|
|
23
69
|
});
|
|
24
70
|
yargs.command({
|
|
25
71
|
command: "run",
|
|
26
72
|
describe: "Run pre-compiled Instance",
|
|
27
|
-
handler:
|
|
28
|
-
if (cfgB !== undefined) {
|
|
29
|
-
const cmd_ct = `
|
|
30
|
-
( (
|
|
31
|
-
) )
|
|
32
|
-
........
|
|
33
|
-
| .VMD |]
|
|
34
|
-
| /
|
|
35
|
-
'----'/_zik...
|
|
36
|
-
`;
|
|
37
|
-
console.warn(`${cmd_ct}`);
|
|
38
|
-
console.warn(
|
|
39
|
-
`Espresso CLI\n--------------\nWarming Up Configs..\nRunning ....\n\nInstance Config:\nConfiguration: ${cfgB.instance}\nEndpoint: localhost:${cfgB.port}\nJSON:`,
|
|
40
|
-
cfgB,
|
|
41
|
-
`\n\nTo stop process press CTRL+C`
|
|
42
|
-
);
|
|
43
|
-
exec(
|
|
44
|
-
`node ./node_modules/cross-env/src/bin/cross-env NODE_ENV=${cfgB.instance} PORT=${cfgB.port} node espresso.js`,
|
|
45
|
-
(error, stdout, stderr) => {
|
|
46
|
-
if (error) {
|
|
47
|
-
console.log(`error: ${error.message}`);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
if (stderr) {
|
|
51
|
-
console.log(`stderr: ${stderr}`);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
console.log(`stdout: ${stdout}`);
|
|
55
|
-
}
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
},
|
|
73
|
+
handler: runCommand,
|
|
59
74
|
});
|
|
60
75
|
yargs.command({
|
|
61
76
|
command: "env",
|
|
@@ -72,21 +87,6 @@ yargs.command({
|
|
|
72
87
|
type: number,
|
|
73
88
|
},
|
|
74
89
|
},
|
|
75
|
-
handler:
|
|
76
|
-
if (argv.instance === undefined) {
|
|
77
|
-
cfgB.instance = cfgB.instance;
|
|
78
|
-
} else if (argv.instance !== cfgB.instance) {
|
|
79
|
-
cfgB.instance = argv.instance;
|
|
80
|
-
}
|
|
81
|
-
if (cfgB.port !== argv.port) {
|
|
82
|
-
cfgB.port = argv.port;
|
|
83
|
-
console.warn("New config saved...");
|
|
84
|
-
} else {
|
|
85
|
-
cfgB.port = cfgB.port;
|
|
86
|
-
console.warn("Config already saved...");
|
|
87
|
-
}
|
|
88
|
-
const instUpdate = JSON.stringify(cfgB);
|
|
89
|
-
fs.writeFileSync("config.json", instUpdate);
|
|
90
|
-
},
|
|
90
|
+
handler: envCommand,
|
|
91
91
|
});
|
|
92
92
|
yargs.parse();
|
|
@@ -4,39 +4,16 @@
|
|
|
4
4
|
* _| _| _| _| _| _| _|
|
|
5
5
|
* _| _| _| _| _| _|
|
|
6
6
|
* _| _| _| _|_|_|
|
|
7
|
-
* EspressoJS -
|
|
7
|
+
* EspressoJS - Init
|
|
8
8
|
*/
|
|
9
9
|
module.exports = (app) => {
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const cfgBuffer = fs.readFileSync("./config.json");
|
|
13
|
-
const cfgBuJSON = cfgBuffer.toString();
|
|
14
|
-
const cfgB = JSON.parse(cfgBuJSON);
|
|
15
|
-
|
|
10
|
+
const { readConfigFile, vmdLogo } = require("config.utils");
|
|
11
|
+
const cfgB = readConfigFile();
|
|
16
12
|
const cmd_header = "We are brewing your Espresso";
|
|
17
|
-
const
|
|
18
|
-
const cmd_ct = `
|
|
19
|
-
( (
|
|
20
|
-
) )
|
|
21
|
-
........
|
|
22
|
-
| .VMD |]
|
|
23
|
-
| /
|
|
24
|
-
'----'/_zik...
|
|
25
|
-
`;
|
|
13
|
+
const cmd_ct = vmdLogo;
|
|
26
14
|
const cmd_ready = "Your Espresso is ready!";
|
|
27
15
|
const cmd_port = `Instance Config\nLive Preview: http://localhost:${
|
|
28
16
|
cfgB.port || process.env.PORT || cfg.port
|
|
29
17
|
}`;
|
|
30
|
-
console.warn(
|
|
31
|
-
`${
|
|
32
|
-
cmd_header +
|
|
33
|
-
cmd_nl +
|
|
34
|
-
cmd_ct +
|
|
35
|
-
cmd_nl +
|
|
36
|
-
cmd_ready +
|
|
37
|
-
cmd_nl +
|
|
38
|
-
cmd_port +
|
|
39
|
-
cmd_nl
|
|
40
|
-
} \n\nTo stop process press CTRL+C`
|
|
41
|
-
);
|
|
18
|
+
console.warn(`${cmd_header}\n${cmd_ct}\n${cmd_ready}\n${cmd_port}\n\nTo stop the process, press CTRL+C`);
|
|
42
19
|
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* _| _| _| _| _|_|_|
|
|
3
|
-
* _| _| _|_| _|_| _| _|
|
|
4
|
-
* _| _| _| _| _| _| _|
|
|
5
|
-
* _| _| _| _| _| _|
|
|
6
|
-
* _| _| _| _|_|_|
|
|
7
|
-
* EspressoJS - EspressoJS / Espresso
|
|
8
|
-
* Dev Template
|
|
9
|
-
*/
|
|
10
|
-
require("dotenv").config();
|
|
11
|
-
const fs = require("fs");
|
|
12
|
-
const configBuffer = fs.readFileSync("./config.json"),
|
|
13
|
-
data = JSON.parse(configBuffer.toString());
|
|
14
|
-
|
|
15
|
-
const config = () => {
|
|
16
|
-
return {
|
|
17
|
-
env: data.instance || "development",
|
|
18
|
-
hostname: data.hostname || "dev.example.com",
|
|
19
|
-
port: data.instance || "8080",
|
|
20
|
-
mongo_isEnabled: data.mongoDB || true,
|
|
21
|
-
mongo: {
|
|
22
|
-
uri: process.env.MONGO_URI || "localhost",
|
|
23
|
-
port: process.env.MONGO_URI_PORT || "27017",
|
|
24
|
-
db: process.env.MONGO_URI_DB || "myFirstDatabase",
|
|
25
|
-
},
|
|
26
|
-
swapi_isEnabled: data.API || true,
|
|
27
|
-
swapi: {
|
|
28
|
-
uri: process.env.API_URI || "https://swapi.dev/api/people/",
|
|
29
|
-
configs: {
|
|
30
|
-
method: process.env.API_METHOD ||"GET",
|
|
31
|
-
url: process.env.API_OBJ_URL || "",
|
|
32
|
-
headers: {
|
|
33
|
-
"Content-Type": "application/json",
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
module.exports = config;
|
|
40
|
-
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* _| _| _| _| _|_|_|
|
|
3
|
-
* _| _| _|_| _|_| _| _|
|
|
4
|
-
* _| _| _| _| _| _| _|
|
|
5
|
-
* _| _| _| _| _| _|
|
|
6
|
-
* _| _| _| _|_|_|
|
|
7
|
-
* EspressoJS - EspressoJS / Espresso
|
|
8
|
-
* Global Template w/ API
|
|
9
|
-
*/
|
|
10
|
-
require("dotenv").config();
|
|
11
|
-
const fs = require("fs");
|
|
12
|
-
const configBuffer = fs.readFileSync("./config.json"),
|
|
13
|
-
data = JSON.parse(configBuffer.toString());
|
|
14
|
-
const config = () => {
|
|
15
|
-
return {
|
|
16
|
-
env: data.instance || "development",
|
|
17
|
-
hostname: data.hostname || "global.example.com",
|
|
18
|
-
port: data.instance || "8080",
|
|
19
|
-
mongo_isEnabled: data.mongoDB || false,
|
|
20
|
-
mongo: {
|
|
21
|
-
uri: process.env.MONGO_URI || "localhost",
|
|
22
|
-
port: process.env.MONGO_URI_PORT || "",
|
|
23
|
-
db: process.env.MONGO_URI_DB || "",
|
|
24
|
-
},
|
|
25
|
-
swapi_isEnabled: data.API ? data.API : true || true,
|
|
26
|
-
swapi: {
|
|
27
|
-
uri: process.env.API_URI || "https://swapi.dev/api/",
|
|
28
|
-
configs: {
|
|
29
|
-
method: process.env.API_METHOD || "GET",
|
|
30
|
-
url: process.env.API_OBJ_URL || "",
|
|
31
|
-
headers: {
|
|
32
|
-
"Content-Type": "application/json",
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
module.exports = config;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* _| _| _| _| _|_|_|
|
|
3
|
-
* _| _| _|_| _|_| _| _|
|
|
4
|
-
* _| _| _| _| _| _| _|
|
|
5
|
-
* _| _| _| _| _| _|
|
|
6
|
-
* _| _| _| _|_|_|
|
|
7
|
-
* EspressoJS - EspressoJS / Espresso
|
|
8
|
-
* Production Template
|
|
9
|
-
*/
|
|
10
|
-
require("dotenv").config();
|
|
11
|
-
const fs = require("fs");
|
|
12
|
-
const configBuffer = fs.readFileSync("./config.json"),
|
|
13
|
-
data = JSON.parse(configBuffer.toString());
|
|
14
|
-
const config = () => {
|
|
15
|
-
return {
|
|
16
|
-
env: data.instance || "production",
|
|
17
|
-
hostname: data.hostname || "www.example.com",
|
|
18
|
-
port: data.instance || "80",
|
|
19
|
-
mongo_isEnabled: data.mongoDB || false,
|
|
20
|
-
mongo: {
|
|
21
|
-
uri: process.env.MONGO_URI || "localhost",
|
|
22
|
-
port: process.env.MONGO_URI_PORT || "27017",
|
|
23
|
-
db: process.env.MONGO_URI_DB || "clients",
|
|
24
|
-
},
|
|
25
|
-
swapi_isEnabled: data.API || false,
|
|
26
|
-
swapi: {
|
|
27
|
-
uri: process.env.API_URI || "https://swapi.dev/api/people/",
|
|
28
|
-
configs: {
|
|
29
|
-
method: process.env.API_METHOD || "GET",
|
|
30
|
-
url: process.env.API_OBJ_URL || "",
|
|
31
|
-
headers: {
|
|
32
|
-
"Content-Type": "application/json",
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
module.exports = config;
|