summary refs log tree commit diff
path: root/src/util/util/TraverseDirectory.ts
blob: 3d0d627902508b6b1f52fc94456f1dc2be314aa4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
import { Server, traverseDirectory } from "lambert-server";

//if we're using ts-node, use ts files instead of js
const extension = Symbol.for("ts-node.register.instance") in process ? "ts" : "js"

const DEFAULT_FILTER = new RegExp("^([^\.].*)(?<!\.d)\.(" + extension + ")$");

export function registerRoutes(server: Server, root: string) {
	return traverseDirectory(
		{ dirname: root, recursive: true, filter: DEFAULT_FILTER },
		server.registerRoute.bind(server, root)
	);
}