@threew/app
Advanced tools
+3
-3
| { | ||
| "name": "@threew/app", | ||
| "version": "1.0.1", | ||
| "version": "1.0.2", | ||
| "main": "./dist/cjs/index.cjs", | ||
@@ -25,4 +25,4 @@ "module": "./dist/esm/index.js", | ||
| }, | ||
| "keywords": [], | ||
| "author": "", | ||
| "keywords": ["threew", "nodejs", "typescript", "backend", "framework", "web", "api", "rest", "server", "http", "router", "middleware", "express", "fast", "lightweight", "performance", "scalable", "body-parser", "logger", "rate-limiter", "static-server", "static-files", "modular"], | ||
| "author": "othreew", | ||
| "license": "ISC", | ||
@@ -29,0 +29,0 @@ "description": "", |
+98
-1
@@ -7,3 +7,2 @@ # @threew/app | ||
| - **Zero Runtime Dependencies**: Built entirely using Node.js native APIs. | ||
| - **Modern Architecture**: Modular design, ready to be split into sub-packages. | ||
@@ -167,4 +166,102 @@ - **TypeScript First**: Full type safety and excellent developer experience. | ||
| ## Static Files | ||
| Serve static files like HTML, CSS, JavaScript, images, and more: | ||
| ### Basic Usage (ESM) | ||
| ```typescript | ||
| import { createApp, staticFiles } from '@threew/app'; | ||
| import path from 'path'; | ||
| const app = createApp(); | ||
| // Serve files from 'public' directory | ||
| app.use(staticFiles(path.join(process.cwd(), 'public'))); | ||
| app.listen(3000); | ||
| ``` | ||
| ### Basic Usage (CommonJS) | ||
| ```javascript | ||
| const { createApp, staticFiles } = require('@threew/app'); | ||
| const path = require('path'); | ||
| const app = createApp(); | ||
| // Serve static files from 'public' folder | ||
| app.use(staticFiles(path.join(__dirname, 'public'))); | ||
| app.listen(3000); | ||
| ``` | ||
| ### With Options | ||
| ```typescript | ||
| app.use(staticFiles(path.join(process.cwd(), 'public'), { | ||
| index: 'index.html', // Default file for directories | ||
| maxAge: 86400000, // Cache duration in ms (1 day) | ||
| etag: true, // Enable ETag header | ||
| cacheControl: true, // Enable Cache-Control header | ||
| dotfiles: 'ignore', // How to handle dotfiles | ||
| lastModified: true, // Enable Last-Modified header | ||
| immutable: false, // Add immutable directive to cache | ||
| setHeaders: (res, filePath, stat) => { | ||
| // Custom headers per file | ||
| if (filePath.endsWith('.html')) { | ||
| res.setHeader('X-Custom', 'HTML file'); | ||
| } | ||
| } | ||
| })); | ||
| ``` | ||
| ### Multiple Directories | ||
| ```typescript | ||
| // Serve from multiple folders (order matters) | ||
| app.use(staticFiles(path.join(process.cwd(), 'public'))); | ||
| app.use(staticFiles(path.join(process.cwd(), 'uploads'))); | ||
| app.use(staticFiles(path.join(process.cwd(), 'assets'))); | ||
| ``` | ||
| ### Manual File Serving | ||
| ```typescript | ||
| import { sendFile } from '@threew/app'; | ||
| // Serve specific file on route | ||
| app.get('/', sendFile(path.join(process.cwd(), 'public', 'index.html'))); | ||
| app.get('/about', sendFile(path.join(process.cwd(), 'public', 'about.html'))); | ||
| ``` | ||
| ### Folder Structure Example | ||
| ``` | ||
| your-project/ | ||
| ├── public/ | ||
| │ ├── index.html | ||
| │ ├── css/ | ||
| │ │ └── style.css | ||
| │ ├── js/ | ||
| │ │ └── app.js | ||
| │ └── images/ | ||
| │ └── logo.png | ||
| ├── src/ | ||
| └── package.json | ||
| ``` | ||
| ### Supported MIME Types | ||
| - HTML, CSS, JavaScript, JSON | ||
| - PNG, JPG, GIF, SVG, ICO, WebP | ||
| - WOFF, WOFF2, TTF, EOT | ||
| - PDF, ZIP, MP3, MP4 | ||
| - And more... | ||
| </details> | ||
| ## License | ||
| MIT |
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
320238
0.78%1
-50%266
57.4%