velocious 1.0.28 → 1.0.29
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/package.json +1 -1
- package/spec/dummy/src/config/routes.js +2 -0
- package/spec/dummy/src/routes/_root/controller.js +11 -0
- package/spec/dummy/src/routes/projects/controller.js +0 -1
- package/spec/http-server/root-get-spec.js +26 -0
- package/src/routes/get-route.js +6 -2
- package/src/routes/resolver.js +3 -1
package/package.json
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import fetch from "node-fetch"
|
|
2
|
+
import Dummy from "../dummy/index.js"
|
|
3
|
+
|
|
4
|
+
describe("HttpServer", () => {
|
|
5
|
+
it("handles root get requests", async () => {
|
|
6
|
+
await Dummy.run(async () => {
|
|
7
|
+
const response = await fetch("http://localhost:3006/ping")
|
|
8
|
+
const text = await response.text()
|
|
9
|
+
|
|
10
|
+
expect(response.status).toEqual(200)
|
|
11
|
+
expect(response.statusText).toEqual("OK")
|
|
12
|
+
expect(text).toEqual("{\"message\":\"Pong\"}")
|
|
13
|
+
})
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it("returns a 404 error when a root get isn't found", async () => {
|
|
17
|
+
await Dummy.run(async () => {
|
|
18
|
+
const response = await fetch("http://localhost:3006/doesnt-exist")
|
|
19
|
+
const text = await response.text()
|
|
20
|
+
|
|
21
|
+
expect(response.status).toEqual(404)
|
|
22
|
+
expect(response.statusText).toEqual("Not Found")
|
|
23
|
+
expect(text).toEqual("Not found!\n")
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
})
|
package/src/routes/get-route.js
CHANGED
|
@@ -10,10 +10,14 @@ export default class VelociousRouteGetRoute extends BaseRoute {
|
|
|
10
10
|
this.regExp = new RegExp(`^(${escapeStringRegexp(name)})(.*)$`)
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
matchWithPath({path}) {
|
|
14
|
-
|
|
13
|
+
matchWithPath({params, path}) {
|
|
14
|
+
const match = path.match(this.regExp)
|
|
15
|
+
|
|
16
|
+
if (match) {
|
|
15
17
|
const [_beginnigSlash, _matchedName, restPath] = match
|
|
16
18
|
|
|
19
|
+
params.action = this.name
|
|
20
|
+
|
|
17
21
|
return {restPath}
|
|
18
22
|
}
|
|
19
23
|
}
|
package/src/routes/resolver.js
CHANGED
|
@@ -33,7 +33,9 @@ export default class VelociousRoutesResolver {
|
|
|
33
33
|
controllerPath = "./built-in/errors/controller.js"
|
|
34
34
|
action = "notFound"
|
|
35
35
|
viewPath = await fs.realpath(`${__dirname}/built-in/errors`) // eslint-disable-line no-undef
|
|
36
|
-
} else if (action
|
|
36
|
+
} else if (action) {
|
|
37
|
+
if (!controller) controller = "_root"
|
|
38
|
+
|
|
37
39
|
controllerPath = `${this.configuration.getDirectory()}/src/routes/${controller}/controller.js`
|
|
38
40
|
viewPath = `${this.configuration.getDirectory()}/src/routes/${controller}`
|
|
39
41
|
} else {
|