fix: let's just force the handlers dir to have an index
This commit is contained in:
parent
9bbece2601
commit
b3a399cf7a
2 changed files with 22 additions and 16 deletions
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "@andyburke/serverus",
|
"name": "@andyburke/serverus",
|
||||||
"description": "A flexible HTTP server for mixed content. Throw static files, markdown, Typescript and (hopefully, eventually) more into a directory and serverus can serve it up a bit more like old-school CGI.",
|
"description": "A flexible HTTP server for mixed content. Throw static files, markdown, Typescript and (hopefully, eventually) more into a directory and serverus can serve it up a bit more like old-school CGI.",
|
||||||
"version": "0.0.7",
|
"version": "0.0.8",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./serverus.ts",
|
".": "./serverus.ts",
|
||||||
|
|
36
server.ts
36
server.ts
|
@ -110,24 +110,30 @@ export class SERVER {
|
||||||
|
|
||||||
for (const handler_directory of HANDLERS_DIRECTORIES) {
|
for (const handler_directory of HANDLERS_DIRECTORIES) {
|
||||||
const root_directory = path.resolve(handler_directory);
|
const root_directory = path.resolve(handler_directory);
|
||||||
|
const index_file = path.join(root_directory, 'index.ts');
|
||||||
|
|
||||||
for await (
|
try {
|
||||||
const entry of walk(root_directory, {
|
const handlers_index = await import(index_file);
|
||||||
exts: ['.ts'],
|
console.dir({
|
||||||
skip: [/\.test\.ts$/]
|
root_directory,
|
||||||
})
|
index_file,
|
||||||
) {
|
handlers_index
|
||||||
if (!entry.isFile) {
|
});
|
||||||
|
for (const handler_name of Object.keys(handlers_index.default)) {
|
||||||
|
const handler_module: HANDLER_MODULE = handlers_index.default[handler_name];
|
||||||
|
if (typeof handler_module?.default !== 'function') {
|
||||||
|
console.warn(`Could not load handler "${handler_name}" - no default exported function`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.handlers.push(handler_module);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof Deno.errors.NotFound) {
|
||||||
|
console.warn(`Could not load handler index from: ${index_file}`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
throw error;
|
||||||
const handler_module: HANDLER_MODULE = await import(entry.path);
|
|
||||||
if (typeof handler_module.default !== 'function') {
|
|
||||||
console.warn(`Could not load handler, no default exported function: ${entry.path}`);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.handlers.push(handler_module);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue