diff --git a/LICENSE.md b/LICENSE similarity index 100% rename from LICENSE.md rename to LICENSE diff --git a/dev/scripts/copy-files.js b/dev/scripts/copy-files.js index 5526a69..55bcb80 100644 --- a/dev/scripts/copy-files.js +++ b/dev/scripts/copy-files.js @@ -1,5 +1,7 @@ // eslint-disable-next-line @typescript-eslint/no-var-requires -const fs = require('fs'); +const fs = require('node:fs'); const target = 'dist'; -['package.json'].forEach((file) => fs.copyFileSync(file, `${target}/${file}`)); +['package.json', 'README.md', 'LICENSE'].forEach((file) => + fs.copyFileSync(file, `${target}/${file}`) +); diff --git a/examples/published-package/api/products.js b/examples/published-package/api/products.js new file mode 100644 index 0000000..e76e08d --- /dev/null +++ b/examples/published-package/api/products.js @@ -0,0 +1,4 @@ +export default function productsHandler(req, res) { + res.setHeader('Content-Type', 'text/html'); + res.end('

Products

'); +} diff --git a/examples/published-package/package.json b/examples/published-package/package.json index 2e714e2..ab52a3a 100644 --- a/examples/published-package/package.json +++ b/examples/published-package/package.json @@ -13,6 +13,6 @@ "node": ">=14.8.0" }, "dependencies": { - "node-file-router": "0.1.0" + "node-file-router": "0.1.3" } } diff --git a/examples/published-package/pnpm-lock.yaml b/examples/published-package/pnpm-lock.yaml index aecc823..c9309a8 100644 --- a/examples/published-package/pnpm-lock.yaml +++ b/examples/published-package/pnpm-lock.yaml @@ -6,12 +6,12 @@ settings: dependencies: node-file-router: - specifier: 0.1.0 - version: 0.1.0 + specifier: 0.1.3 + version: 0.1.3 packages: - /node-file-router@0.1.0: - resolution: {integrity: sha512-PTPqD8MdNcbPxf4Ty4ZDstULxGoQgeKcCFJ1qGlwj74uZQ3CYK2Yb1kUmuLI+s5Q+3NcC6RAW/DR2X9LwAEDKw==} + /node-file-router@0.1.3: + resolution: {integrity: sha512-SDorA7uwOTa8RPMKWsb2tsXMDYibfvAbpeocwi84f73au4ceihi0J0/nkoxVEwXB8kzcbchOrJUxeIs/SUB2PA==} engines: {node: '>=14.8.0'} dev: false diff --git a/examples/published-package/server.js b/examples/published-package/server.js index e3d40a5..b02031e 100644 --- a/examples/published-package/server.js +++ b/examples/published-package/server.js @@ -2,7 +2,7 @@ import * as http from 'node:http'; import { initFileRouter } from 'node-file-router'; async function run() { - const useFileRouter = await initFileRouter({ baseDir: `${__filename}/api` }); + const useFileRouter = await initFileRouter({}); const server = http.createServer((req, res) => { useFileRouter(req, res); diff --git a/package.json b/package.json index 59ab038..03ce781 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-file-router", - "version": "0.1.0", + "version": "0.1.3", "description": "A file-based routing for Node.js", "scripts": { "build:esm": "cross-env BABEL_ENV=esm babel src --extensions '.ts' --out-dir 'dist/esm' --out-file-extension .mjs --source-maps", @@ -17,7 +17,6 @@ "module": "./esm/file-router.mjs", "main": "../cjs/file-router.js", "types": "./types/file-router.d.ts", - "files": ["dist"], "exports": { "import": "./esm/file-router.mjs", "require": "./cjs/file-router.js" diff --git a/src/file-router.ts b/src/file-router.ts index 97d4809..aede32a 100644 --- a/src/file-router.ts +++ b/src/file-router.ts @@ -16,7 +16,7 @@ export async function initFileRouter({ baseDir = path.join(process.cwd(), '/api'), ignoreFilesRegex, adapter = httpAdapter -}: Options) { +}: Options = {}) { const { getPathname, defaultNotFoundHandler, getMethod } = adapter; const fileRouteResolver = new FileRouteResolver({ baseDir,