@stanlemon/server 0.3.46 → 0.4.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.
package/app.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  NotFoundException,
5
5
  } from "./src/index.js";
6
6
 
7
- const app = createAppServer({ port: 3003 });
7
+ export const app = createAppServer({ port: 3003 });
8
8
 
9
9
  // curl http://localhost:3003/hello?name=Stanley
10
10
  app.get(
package/app.test.js ADDED
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @jest-environment node
3
+ */
4
+ import request from "supertest";
5
+ import { app } from "./app.js";
6
+
7
+ describe("/app", () => {
8
+ it("GET /hello", async () => {
9
+ // Happy path 200 use case
10
+ const response = await request(app)
11
+ .get("/hello")
12
+ .set("Accept", "application/json");
13
+
14
+ expect(response.headers["content-type"]).toMatch(/json/);
15
+ expect(response.status).toEqual(200);
16
+ expect(response.body).toEqual({ hello: "Stan" });
17
+ });
18
+
19
+ it("GET /hello/Stan", async () => {
20
+ // This endpoint explicitly 404s
21
+ const response = await request(app)
22
+ .get("/hello/Stan")
23
+ .set("Accept", "application/json");
24
+
25
+ expect(response.headers["content-type"]).toMatch(/json/);
26
+ expect(response.status).toEqual(404);
27
+ expect(response.body).toEqual({ error: "Not Found" });
28
+ });
29
+
30
+ it("GET /hello/Sara", async () => {
31
+ // Custom parameter 200
32
+ const response = await request(app)
33
+ .get("/hello/Sara")
34
+ .set("Accept", "application/json");
35
+
36
+ expect(response.headers["content-type"]).toMatch(/json/);
37
+ expect(response.status).toEqual(200);
38
+ expect(response.body).toEqual({ hello: "Sara" });
39
+ });
40
+
41
+ it("POST /hello", async () => {
42
+ // POST request with JSON body 200
43
+ const response = await request(app)
44
+ .post("/hello")
45
+ .set("Accept", "application/json")
46
+ .send({ name: "Henry" });
47
+
48
+ expect(response.headers["content-type"]).toMatch(/json/);
49
+ expect(response.status).toEqual(200);
50
+ expect(response.body).toEqual({ hello: "Henry" });
51
+ });
52
+
53
+ it("GET 404 on undefined api path", async () => {
54
+ const response = await request(app)
55
+ .get("/not-found")
56
+ .set("Accept", "application/json");
57
+
58
+ expect(response.status).toEqual(404);
59
+ });
60
+ });
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@stanlemon/server",
3
- "version": "0.3.46",
3
+ "version": "0.4.0",
4
4
  "description": "A basic express web server setup.",
5
5
  "author": "Stan Lemon <stanlemon@users.noreply.github.com>",
6
6
  "license": "MIT",
7
7
  "engines": {
8
- "node": ">=22.12.0"
8
+ "node": ">=22.14.0"
9
9
  },
10
10
  "type": "module",
11
11
  "main": "./src/index.js",
@@ -24,7 +24,7 @@
24
24
  "compression": "^1.8.0",
25
25
  "cookie-parser": "^1.4.7",
26
26
  "dotenv": "16.4.7",
27
- "express": "^4.21.2",
27
+ "express": "^5.1.0",
28
28
  "express-rate-limit": "^7.5.0",
29
29
  "helmet": "^8.1.0",
30
30
  "http-proxy-middleware": "^3.0.3",
@@ -75,7 +75,7 @@ export default function createAppServer(options) {
75
75
  console.info("Proxying webpack dev server");
76
76
 
77
77
  app.get(
78
- "/static/*",
78
+ "/static/*splat",
79
79
  createProxyMiddleware({
80
80
  target: webpack,
81
81
  changeOrigin: true,
@@ -120,25 +120,25 @@ export default function createAppServer(options) {
120
120
  app.spa = () => {
121
121
  if (useWebpack) {
122
122
  app.get(
123
- "*",
123
+ "/*splat",
124
124
  createProxyMiddleware({
125
125
  target: webpack,
126
126
  changeOrigin: true,
127
127
  })
128
128
  );
129
129
  } else {
130
- app.get(`*`, function (req, res, next) {
130
+ app.get(`/*splat`, function (req, res, next) {
131
131
  res.sendFile(path.resolve("./", "dist", "index.html"));
132
132
  });
133
133
  }
134
134
  };
135
135
 
136
- app.catch404s = (path = "/*") => {
136
+ app.catch404s = (path = "/") => {
137
137
  const router = Router();
138
138
  router.use((req, res, next) => {
139
139
  res.status(404).json({ error: "Not Found" });
140
140
  });
141
- app.use(path, router);
141
+ app.use(`${path}*splat`, router);
142
142
  };
143
143
 
144
144
  // If we're set to start. Btw we never start in test.