You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
689 B
23 lines
689 B
7 years ago
|
import PromiseRouter from "express-promise-router";
|
||
|
|
||
|
import ApiError from "@common/ApiError";
|
||
|
import { ErrorCode } from "@common/ErrorCode";
|
||
|
import { authentication } from "@server/express/authentication";
|
||
|
import { ServerState } from "@server/state";
|
||
|
import { devices } from "./devices";
|
||
|
import { users } from "./users";
|
||
|
|
||
|
export default function createApi(state: ServerState) {
|
||
|
const router = PromiseRouter();
|
||
|
|
||
|
router.use("/devices", devices(state));
|
||
|
router.use("/users", users(state));
|
||
|
router.use("/token", authentication(state));
|
||
|
|
||
|
router.use("*", (req, res) => {
|
||
|
throw new ApiError("API endpoint not found", ErrorCode.NotFound);
|
||
|
});
|
||
|
|
||
|
return router;
|
||
|
}
|