@misterzik/espressojs 3.3.1 → 3.3.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,30 @@
2
2
 
3
3
  All notable changes to EspressoJS will be documented in this file.
4
4
 
5
+ ## [3.3.3] - 2024-12-24
6
+
7
+ ### Fixed
8
+ - Server startup crash when favicon or public directory missing
9
+ - Configuration property names in routes (api.enabled, mongoDB.enabled)
10
+ - Public directory path handling (supports both absolute and relative paths)
11
+ - CLI spawn process simplified (removed cross-env dependency)
12
+ - Enhanced error logging with stack traces
13
+
14
+ ### Changed
15
+ - Updated dependencies to latest stable versions
16
+ - Replaced deprecated babel-preset-env with @babel/preset-env
17
+ - Made favicon and static file serving optional with graceful fallbacks
18
+
19
+ ### Security
20
+ - Fixed 22 critical vulnerabilities by updating Babel dependencies
21
+ - Updated axios, joi, and mongoose to latest versions
22
+
23
+ ## [3.3.2] - 2024-12-24
24
+
25
+ ### Fixed
26
+ - Package publishing configuration
27
+ - Updated .npmignore to exclude development files
28
+
5
29
  ## [3.3.1] - 2024-01-01
6
30
 
7
31
  ### Added
package/index.js CHANGED
@@ -49,7 +49,10 @@ const {
49
49
  const Port = configData.port || cfg.port;
50
50
  const mongoConfig = configData.mongoDB;
51
51
  const rootDir = process.cwd();
52
- const publicDir = configData.publicDirectory || "/public";
52
+ const publicDir = configData.publicDirectory || "public";
53
+ const publicPath = publicDir.startsWith('/') || publicDir.startsWith('\\')
54
+ ? publicDir.substring(1)
55
+ : publicDir;
53
56
 
54
57
  validateEnvVariables();
55
58
 
@@ -102,15 +105,28 @@ app.get("/health", healthCheck);
102
105
  app.get("/ready", readinessCheck);
103
106
  app.get("/alive", livenessCheck);
104
107
 
105
- app.use(Favicon(Path.join(rootDir, publicDir, "favicon.ico")));
106
- app.use(
107
- Static(Path.join(rootDir, publicDir), {
108
- maxAge: "1d",
109
- setHeaders: setCustomCacheControl,
110
- etag: true,
111
- extensions: "error.html",
112
- })
113
- );
108
+ const fs = require("fs");
109
+ const faviconPath = Path.join(rootDir, publicPath, "favicon.ico");
110
+ if (fs.existsSync(faviconPath)) {
111
+ app.use(Favicon(faviconPath));
112
+ } else {
113
+ logger.warn(`Favicon not found at ${faviconPath}, skipping...`);
114
+ }
115
+
116
+ const staticPath = Path.join(rootDir, publicPath);
117
+ if (fs.existsSync(staticPath)) {
118
+ app.use(
119
+ Static(staticPath, {
120
+ maxAge: "1d",
121
+ setHeaders: setCustomCacheControl,
122
+ etag: true,
123
+ extensions: "error.html",
124
+ })
125
+ );
126
+ logger.info(`Static files served from: ${staticPath}`);
127
+ } else {
128
+ logger.warn(`Public directory not found at ${staticPath}, skipping static file serving...`);
129
+ }
114
130
 
115
131
  Routes(app);
116
132
 
@@ -167,11 +183,18 @@ process.on("unhandledRejection", (reason, promise) => {
167
183
 
168
184
  process.on("uncaughtException", (error) => {
169
185
  logger.error(`Uncaught Exception: ${error.message}`);
186
+ logger.error(`Stack: ${error.stack}`);
170
187
  gracefulShutdown("UNCAUGHT_EXCEPTION");
171
188
  });
172
189
 
173
190
  if (require.main === module) {
174
- startServer();
191
+ try {
192
+ startServer();
193
+ } catch (error) {
194
+ logger.error(`Failed to start server: ${error.message}`);
195
+ logger.error(`Stack: ${error.stack}`);
196
+ process.exit(1);
197
+ }
175
198
  }
176
199
 
177
200
  module.exports = app;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@misterzik/espressojs",
3
- "version": "3.3.1",
3
+ "version": "3.3.3",
4
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": {
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "homepage": "https://github.com/misterzik/Espresso.js#readme",
38
38
  "dependencies": {
39
- "axios": "^1.6.0",
39
+ "axios": "^1.6.5",
40
40
  "bluebird": "^3.7.2",
41
41
  "compression": "^1.7.4",
42
42
  "cors": "^2.8.5",
@@ -47,8 +47,8 @@
47
47
  "express-validator": "^7.0.1",
48
48
  "finalhandler": "^1.2.0",
49
49
  "helmet": "^7.1.0",
50
- "joi": "^17.11.0",
51
- "mongoose": "^8.0.3",
50
+ "joi": "^17.12.0",
51
+ "mongoose": "^8.0.4",
52
52
  "morgan": "^1.10.0",
53
53
  "serve-favicon": "^2.5.0",
54
54
  "serve-static": "^1.15.0",
@@ -56,11 +56,11 @@
56
56
  "yargs": "^17.7.2"
57
57
  },
58
58
  "devDependencies": {
59
- "debug": "^4.3.4",
60
- "@babel/core": "^7.22.5",
59
+ "debug": "^4.3.7",
60
+ "@babel/core": "^7.23.7",
61
+ "@babel/preset-env": "^7.23.7",
61
62
  "amd-define-factory-patcher-loader": "^1.0.0",
62
- "babel-loader": "^9.1.2",
63
- "babel-preset-env": "^1.7.0"
63
+ "babel-loader": "^9.1.3"
64
64
  },
65
65
  "engines": {
66
66
  "node": ">= 0.10.0"
package/routes/index.js CHANGED
@@ -11,10 +11,11 @@
11
11
 
12
12
  const path = require("path");
13
13
  const fs = require("fs");
14
- const configuration = require("../server");
14
+ const { readConfigFile } = require("../server/utils/config.utils");
15
15
  const logger = require("../server/utils/logger");
16
16
  const { asyncHandler } = require("../server/middleware/errorHandler");
17
17
  const rootDir = process.cwd();
18
+ const configuration = readConfigFile();
18
19
 
19
20
  module.exports = (app) => {
20
21
  app.get(
@@ -26,7 +27,7 @@ module.exports = (app) => {
26
27
  logger.warn("index.html not found, sending default response");
27
28
  return res.status(200).json({
28
29
  message: "Welcome to EspressoJS",
29
- version: "3.2.6",
30
+ version: "3.3.2",
30
31
  documentation: "https://github.com/misterzik/Espresso.js",
31
32
  });
32
33
  }
@@ -35,7 +36,7 @@ module.exports = (app) => {
35
36
  })
36
37
  );
37
38
 
38
- if (configuration.api_isEnabled === true) {
39
+ if (configuration.api && configuration.api.enabled === true) {
39
40
  try {
40
41
  const apiRoutes = require(path.join(rootDir, "routes", "api.js"));
41
42
  app.use("/api", apiRoutes);
@@ -45,7 +46,7 @@ module.exports = (app) => {
45
46
  }
46
47
  }
47
48
 
48
- if (configuration.mongo_isEnabled === true) {
49
+ if (configuration.mongoDB && configuration.mongoDB.enabled === true) {
49
50
  try {
50
51
  const dbRoutes = require(path.join(rootDir, "routes", "db.js"));
51
52
  app.use("/api/db", dbRoutes);
@@ -44,8 +44,16 @@ JSON:`,
44
44
 
45
45
  const child = spawn(
46
46
  "node",
47
- ["./node_modules/cross-env/src/bin/cross-env", `NODE_ENV=${cfgB.instance}`, `PORT=${cfgB.port}`, "node", "index.js"],
48
- { stdio: "inherit", shell: true }
47
+ ["index.js"],
48
+ {
49
+ stdio: "inherit",
50
+ shell: true,
51
+ env: {
52
+ ...process.env,
53
+ NODE_ENV: cfgB.instance,
54
+ PORT: cfgB.port.toString()
55
+ }
56
+ }
49
57
  );
50
58
 
51
59
  child.on("error", (error) => {
@@ -56,6 +64,7 @@ JSON:`,
56
64
  if (code !== 0) {
57
65
  console.error(`Process exited with code ${code}`);
58
66
  }
67
+ process.exit(code);
59
68
  });
60
69
  }
61
70
  }
package/.env DELETED
@@ -1,3 +0,0 @@
1
- MONGO_USER=USER
2
- MONGO_TOKEN=PASSWORD
3
- API_TOKEN=APITOKEN