Skip to content

Commit

Permalink
fix(endpoints): Endpoints not being read on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Kathund committed Nov 20, 2023
1 parent 6e32b58 commit e9088f4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { PORT } from "./config.json";
import express from "express";
import { join } from "path";

const filesDir = join(__dirname, "src", "files");
const filesDir = join(__dirname, "src", "files");
if (!existsSync(filesDir)) {
mkdirSync(filesDir);
}
Expand All @@ -20,7 +20,7 @@ try {
const result = loadEndpoints(endpointsDir, app);
if (result !== undefined) {
otherMessage(
`Loaded ${result.loaded} endpoints, skipped ${result.skipped} endpoints`
`Loaded ${result.loaded} endpoints, skipped ${result.skipped} endpoints`,
);
} else {
otherMessage(`No endpoints found in ${endpointsDir}`);
Expand Down
18 changes: 9 additions & 9 deletions src/helper.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { otherMessage, errorMessage } from './logger';
import { readdirSync, statSync } from 'fs';
import { Application } from 'express';
import { join } from 'path';
import { otherMessage, errorMessage } from "./logger";
import { readdirSync, statSync } from "fs";
import { Application } from "express";
import { basename, join } from "path";

export const loadEndpoints = (directory: string, app: Application) => {
try {
const items = readdirSync(directory);
console.log(items);

let skipped = 0;
let loaded = 0;
Expand All @@ -19,20 +20,19 @@ export const loadEndpoints = (directory: string, app: Application) => {
skipped += result.skipped;
loaded += result.loaded;
}
} else if (item.toLowerCase().endsWith('.ts')) {
if (item.toLowerCase().includes('disabled')) {
} else if (item.toLowerCase().endsWith(".ts")) {
if (item.toLowerCase().includes("disabled")) {
skipped++;
continue;
}
loaded++;
// eslint-disable-next-line
const route = require(itemPath).default;
route(app);
otherMessage(`Loaded ${itemPath.split('/src/endpoints/')[1].split('.ts')[0]} endpoint`);
otherMessage(`Loaded ${basename(itemPath).split(".ts")[0]} endpoint`);
}
}
return { loaded, skipped };
} catch (error: any) {
errorMessage(`Error loading endpoints: ${error}`);
}
};
};
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"strict": true,
"target": "es2016",
"target": "ES2021",
"outDir": "./dist",
"module": "CommonJS",
"skipLibCheck": true,
Expand Down

0 comments on commit e9088f4

Please sign in to comment.