satto 1.0.9 → 1.1.1

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 +4 -36
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "satto",
3
- "version": "1.0.9",
3
+ "version": "1.1.1",
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();
@@ -86,12 +64,10 @@ function createServer(__dirname, routes = [], port = 3000) {
86
64
  app.set("views", path.join(__dirname, "app"));
87
65
  app.engine("html", ejs.renderFile);
88
66
  app.set("view engine", "html");
89
-
90
- app.use(express.static(path.join(__dirname, "app")));
91
67
  app.use(express.static(path.join(__dirname, "static")));
92
68
 
93
69
  routes.forEach((route) => {
94
- app.get(route.path, (req, res, next) => {
70
+ app.get(route.path, (req, res) => {
95
71
  const page = route.page;
96
72
  const htmlPath = path.join(__dirname, "app", page, page + ".html");
97
73
  app.use(express.static(path.join(__dirname, "app", page)));
@@ -99,7 +75,7 @@ function createServer(__dirname, routes = [], port = 3000) {
99
75
  fs.readFile(htmlPath, "utf8", async (err, html) => {
100
76
  try {
101
77
  if (err) {
102
- return next();
78
+ res.status(404).send();
103
79
  }
104
80
 
105
81
  const params = { ...req.params };
@@ -125,21 +101,13 @@ function createServer(__dirname, routes = [], port = 3000) {
125
101
 
126
102
  res.send(await renderPage(html, params));
127
103
  } catch (err) {
128
- next(err);
104
+ console.error(err);
105
+ res.status(500).send();
129
106
  }
130
107
  });
131
108
  });
132
109
  });
133
110
 
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
111
  app.listen(port, () => {
144
112
  const banner = [
145
113
  " ____ _ _ ",