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 CHANGED
@@ -3,7 +3,7 @@
3
3
  "velocious": "bin/velocious.js"
4
4
  },
5
5
  "name": "velocious",
6
- "version": "1.0.28",
6
+ "version": "1.0.29",
7
7
  "main": "index.js",
8
8
  "scripts": {
9
9
  "test": "jasmine",
@@ -8,6 +8,8 @@ routes.draw((route) => {
8
8
  route.resources("tasks", (route) => {
9
9
  route.get("users")
10
10
  })
11
+
12
+ route.get("ping")
11
13
  })
12
14
 
13
15
  export default {routes}
@@ -0,0 +1,11 @@
1
+ import Controller from "../../../../../src/controller.js"
2
+
3
+ export default class RootController extends Controller {
4
+ ping() {
5
+ this.render({
6
+ json: {
7
+ message: "Pong"
8
+ }
9
+ })
10
+ }
11
+ }
@@ -2,7 +2,6 @@ import {digg} from "diggerize"
2
2
 
3
3
  import Controller from "../../../../../src/controller.js"
4
4
  import Project from "../../models/project.js"
5
- import Task from "../../models/task.js"
6
5
 
7
6
  export default class ProjectsController extends Controller {
8
7
  index() {
@@ -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
+ })
@@ -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
- if (path.match(this.regExp)) {
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
  }
@@ -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 && controller) {
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 {