satto 1.0.9 → 1.1.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/lib/index.js +3 -33
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "satto",
3
- "version": "1.0.9",
3
+ "version": "1.1.0",
4
4
  "description": "A minimal server-rendered web framework for Node.js",
5
5
  "main": "src/lib/index.js",
6
6
  "bin": {
package/src/lib/index.js CHANGED
@@ -57,28 +57,6 @@ async function renderPage(html, params) {
57
57
  }
58
58
  }
59
59
 
60
- function renderErrorPage(code, message) {
61
- return `
62
- <style>
63
- body {
64
- margin: 0;
65
- height: 100vh;
66
- display: flex;
67
- justify-content: center;
68
- align-items: center;
69
- background: black;
70
- color: white;
71
- font-family: system-ui, sans-serif;
72
- }
73
- h1 {
74
- font-size: 2rem;
75
- font-weight: 400;
76
- }
77
- </style>
78
- <h1>${code} — ${message}</h1>
79
- `;
80
- }
81
-
82
60
  function createServer(__dirname, routes = [], port = 3000) {
83
61
  const versionApp = Date.now();
84
62
  const app = express();
@@ -99,7 +77,7 @@ function createServer(__dirname, routes = [], port = 3000) {
99
77
  fs.readFile(htmlPath, "utf8", async (err, html) => {
100
78
  try {
101
79
  if (err) {
102
- return next();
80
+ res.status(404).send();
103
81
  }
104
82
 
105
83
  const params = { ...req.params };
@@ -125,21 +103,13 @@ function createServer(__dirname, routes = [], port = 3000) {
125
103
 
126
104
  res.send(await renderPage(html, params));
127
105
  } catch (err) {
128
- next(err);
106
+ console.error(err);
107
+ res.status(500).send();
129
108
  }
130
109
  });
131
110
  });
132
111
  });
133
112
 
134
- app.use((req, res) => {
135
- res.status(404).send(renderErrorPage(404, "Page Not Found"));
136
- });
137
-
138
- app.use((err, req, res, next) => {
139
- console.error(err);
140
- res.status(500).send(renderErrorPage(500, "Internal Server Error"));
141
- });
142
-
143
113
  app.listen(port, () => {
144
114
  const banner = [
145
115
  " ____ _ _ ",