Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
✨ Add root controller
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Mar 4, 2020
1 parent 088065e commit eb9ee6e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@staart/api",
"version": "1.3.104",
"version": "1.3.105",
"main": "index.js",
"repository": "[email protected]:staart/api.git",
"author": "Anand Chowdhary <[email protected]>",
Expand Down Expand Up @@ -90,5 +90,5 @@
"setup"
],
"snyk": true,
"staart-version": "1.3.104"
"staart-version": "1.3.105"
}
31 changes: 15 additions & 16 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import "@babel/polyfill";
import { Server } from "@staart/server";
import { Server, Get, Controller } from "@staart/server";
import { success } from "@staart/errors";
import { setupMiddleware, Request, Response } from "@staart/server";

// `join` is required
import { join } from "path";
import { setupMiddleware } from "@staart/server";

import {
errorHandler,
Expand All @@ -13,11 +10,23 @@ import {
speedLimitHandler
} from "./helpers/middleware";

@Controller("/")
class RootController {
@Get()
async info() {
return {
repository: "https://github.com/staart/api",
docs: "https://staart.js.org",
madeBy: ["https://o15y.com", "https://anandchowdhary.com"]
};
}
}

export class Staart extends Server {
constructor() {
super();
this.setupHandlers();
this.setupControllers();
this.addControllers([new RootController()]);
this.app.use(errorHandler);
}

Expand All @@ -28,16 +37,6 @@ export class Staart extends Server {
this.app.use(speedLimitHandler);
}

private setupControllers() {
this.app.get("/", (req: Request, res: Response) =>
res.json({
repository: "https://github.com/staart/api",
docs: "https://staart.js.org"
})
);
// staart:setup/controllers
}

public start(port: number): void {
this.app.listen(port, () => success(`Listening on ${port}`));
}
Expand Down

0 comments on commit eb9ee6e

Please sign in to comment.