Skip to content

Commit 2c38204

Browse files
committed
Fix asterisk name usages
1 parent 2984559 commit 2c38204

File tree

5 files changed

+39
-10
lines changed

5 files changed

+39
-10
lines changed

apps/template/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ app.delete(
5858
);
5959

6060
app.spa();
61-
app.catch404s("/api/*");
61+
app.catch404s("/api/");

packages/server-with-auth/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ app.get(
5353
}))
5454
);
5555

56-
app.catch404s("/api/*");
56+
app.catch404s("/api/");

packages/server-with-auth/app.test.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ import request from "supertest";
55
import { app } from "./app.js";
66
import { signupAndLogin } from "./src/utilities/testUtils.js";
77

8-
const username = "test" + Math.random();
9-
const password = "p@$$w0rd!";
10-
118
describe("/app", () => {
129
it("Insecure endpoint", async () => {
1310
// Insecure endpoint
@@ -29,6 +26,7 @@ describe("/app", () => {
2926
});
3027

3128
it("Secure endpoint with auth", async () => {
29+
const { username, password } = makeUsernameAndPassword();
3230
const session = await signupAndLogin(app, username, password, {
3331
email: "test@test.com",
3432
fullName: "Test User",
@@ -50,4 +48,27 @@ describe("/app", () => {
5048
})
5149
);
5250
});
51+
52+
it("404 on undefined api path", async () => {
53+
const { username, password } = makeUsernameAndPassword();
54+
const session = await signupAndLogin(app, username, password, {
55+
email: "test@test.com",
56+
fullName: "Test User",
57+
});
58+
59+
const token = session.token;
60+
61+
const response = await request(app)
62+
.get("/api/not-found")
63+
.set("Accept", "application/json")
64+
.set("Authorization", "Bearer " + token);
65+
66+
expect(response.status).toEqual(404);
67+
});
5368
});
69+
70+
function makeUsernameAndPassword() {
71+
const username = "test" + Math.random();
72+
const password = "p@$$w0rd!";
73+
return { username, password };
74+
}

packages/server/app.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,12 @@ describe("/app", () => {
4949
expect(response.status).toEqual(200);
5050
expect(response.body).toEqual({ hello: "Henry" });
5151
});
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+
});
5260
});

packages/server/src/createAppServer.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export default function createAppServer(options) {
7575
console.info("Proxying webpack dev server");
7676

7777
app.get(
78-
"/static/*",
78+
"/static/*splat",
7979
createProxyMiddleware({
8080
target: webpack,
8181
changeOrigin: true,
@@ -120,25 +120,25 @@ export default function createAppServer(options) {
120120
app.spa = () => {
121121
if (useWebpack) {
122122
app.get(
123-
"*",
123+
"/*splat",
124124
createProxyMiddleware({
125125
target: webpack,
126126
changeOrigin: true,
127127
})
128128
);
129129
} else {
130-
app.get(`*`, function (req, res, next) {
130+
app.get(`/*splat`, function (req, res, next) {
131131
res.sendFile(path.resolve("./", "dist", "index.html"));
132132
});
133133
}
134134
};
135135

136-
app.catch404s = (path = "/*") => {
136+
app.catch404s = (path = "/") => {
137137
const router = Router();
138138
router.use((req, res, next) => {
139139
res.status(404).json({ error: "Not Found" });
140140
});
141-
app.use(path, router);
141+
app.use(`${path}*splat`, router);
142142
};
143143

144144
// If we're set to start. Btw we never start in test.

0 commit comments

Comments
 (0)