{"id":24091405,"url":"https://github.com/srdjan/deno-server","last_synced_at":"2026-05-16T18:09:25.150Z","repository":{"id":270120130,"uuid":"908362362","full_name":"srdjan/deno-server","owner":"srdjan","description":"A lightweight, functional-style HTTP server built with Deno and Effection.","archived":false,"fork":false,"pushed_at":"2025-01-23T22:55:46.000Z","size":79,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-29T03:04:26.033Z","etag":null,"topics":["deno","effection"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/srdjan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-25T21:38:10.000Z","updated_at":"2025-01-23T22:55:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"f4a1ea6f-4125-4a98-b864-466da55636e9","html_url":"https://github.com/srdjan/deno-server","commit_stats":null,"previous_names":["srdjan/deno-server"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/srdjan/deno-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srdjan%2Fdeno-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srdjan%2Fdeno-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srdjan%2Fdeno-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srdjan%2Fdeno-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/srdjan","download_url":"https://codeload.github.com/srdjan/deno-server/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srdjan%2Fdeno-server/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262842925,"owners_count":23373167,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deno","effection"],"created_at":"2025-01-10T07:43:58.258Z","updated_at":"2026-05-16T18:09:20.128Z","avatar_url":"https://github.com/srdjan.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# **Deno HTTP Server with Static File Serving and Dynamic Routing**\n\nA robust, functional-style HTTP server built with **Deno** and **Effection**. This server implements secure static file serving, dynamic routing with RegExp support, comprehensive middleware system, and advanced structured concurrency patterns.\n\n---\n\n## **Features**\n\n- **Enhanced Static File Serving**: Secure static file serving with path traversal protection and MIME type caching\n- **Advanced Dynamic Routing**: Define routes with `path` (string or RegExp), `method`, and `handler`\n- **Comprehensive Middleware**: Built-in middleware for logging, security headers, and request tracking\n- **Advanced Structured Concurrency**: Leverages Effection for robust resource management and graceful shutdown\n- **Security Features**: Strong security defaults with CSP and other security headers\n- **Request Tracking**: Monitor and manage in-flight requests during shutdown\n- **Environment Configuration**: Flexible configuration through environment variables\n- **Structured Logging**: Detailed request logging with unique request IDs and timing\n\n---\n\n## **Getting Started**\n\n### **Prerequisites**\n\n- [Deno](https://deno.land/) 1.37 or higher installed on your machine\n- Understanding of TypeScript and async programming\n\n### **Installation**\n\n1. Clone the repository:\n\n   ```bash\n   git clone https://github.com/your-username/deno-http-server.git\n   cd deno-http-server\n   ```\n\n2. Create a `public` directory for static files:\n\n   ```bash\n   mkdir public\n   ```\n\n3. Configure environment variables (optional):\n\n   ```bash\n   export PORT=8000\n   export DENO_ENV=development\n   export PUBLIC_DIR=./public\n   export SHUTDOWN_TIMEOUT=5000\n   ```\n\n### **Running the Server**\n\n1. Start the server:\n\n   ```bash\n   deno run --allow-net --allow-read --allow-env routes.ts\n   ```\n\n2. The server will start on `http://localhost:8000` (or configured PORT).\n\n---\n\n## **Project Structure**\n\n```\n.\n├── server/              # Server implementation\n│   ├── server.ts        # Main server implementation\n│   └── deps.ts          # Dependency management\n├── routes.ts            # Application routes\n├── public/              # Directory for static files\n│   ├── index.html       # Example HTML file\n│   ├── styles.css       # Example CSS file\n│   └── 404.html        # Custom 404 error page\n└── README.md           # This file\n```\n\n---\n\n## **Defining Routes**\n\nRoutes now support RegExp patterns and include Effection context:\n\n```typescript\n// routes.ts\nimport { Route, serveStatic, start } from \"../server/server.ts\";\n\nconst routes: Route[] = [\n  {\n    path: \"/\",\n    method: \"GET\",\n    handler: async (req, context) =\u003e new Response(\"Hello, World!\", { status: 200 }),\n  },\n  {\n    path: /^\\/users\\/(\\d+)$/,  // RegExp pattern for dynamic routes\n    method: \"GET\",\n    handler: async (req, context) =\u003e new Response(\"User details\", { status: 200 }),\n  },\n  {\n    path: \"/static\",\n    method: \"GET\",\n    handler: async (req, context) =\u003e {\n      const url = new URL(req.url);\n      const filePath = `./public${url.pathname.substring(\"/static\".length)}`;\n      return await serveStatic(filePath, context);\n    },\n  },\n];\n\nstart(routes);\n```\n\n---\n\n## **Middleware**\n\nThe server now includes enhanced middleware capabilities:\n\n```typescript\n// Example custom middleware with context\nconst customMiddleware = (handler: RequestHandler): RequestHandler =\u003e \n  async (req, context) =\u003e {\n    const response = await handler(req, context);\n    // Middleware logic here\n    return response;\n  };\n\n// Built-in middleware includes:\n// - Logging middleware with request tracking\n// - Security headers middleware with configurable CSP\n// - Request tracking middleware for graceful shutdown\n```\n\n### **Security Headers**\n\nBuilt-in security headers include:\n\n```typescript\n{\n  \"Content-Security-Policy\": \"default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline';\",\n  \"X-Content-Type-Options\": \"nosniff\",\n  \"X-Frame-Options\": \"DENY\",\n  \"Strict-Transport-Security\": \"max-age=31536000; includeSubDomains\",\n  \"X-XSS-Protection\": \"1; mode=block\"\n}\n```\n\n---\n\n## **Static File Serving**\n\nEnhanced static file serving features:\n\n- Path traversal protection\n- Cached MIME type mapping\n- Secure file access within public directory\n- Proper error handling for missing files\n\n---\n\n## **Advanced Features**\n\n### **Request Tracking**\n\n```typescript\nconst requestTracker = createRequestTracker();\n// Tracks in-flight requests for graceful shutdown\nyield* requestTracker.track(requestPromise);\n```\n\n### **Graceful Shutdown**\n\nThe server now implements comprehensive shutdown handling:\n\n1. Captures SIGINT and SIGTERM signals\n2. Stops accepting new connections\n3. Waits for in-flight requests to complete (with timeout)\n4. Cleans up resources using Effection context\n5. Logs shutdown progress\n\n### **Structured Logging**\n\nExample log output:\n\n```json\n{\n  \"requestId\": \"uuid\",\n  \"method\": \"GET\",\n  \"url\": \"/path\",\n  \"status\": 200,\n  \"duration\": 123,\n  \"timestamp\": \"2024-12-30T12:00:00.000Z\"\n}\n```\n\n---\n\n## **Error Handling**\n\n- Development mode: Detailed error messages\n- Production mode: Generic error responses\n- Proper error propagation through Effection context\n- Comprehensive error logging\n\n---\n\n## **Example Requests**\n\nSame as before, plus:\n\n- **Dynamic User Route**:\n\n  ```bash\n  curl http://localhost:8000/users/123\n  ```\n\n---\n\n## **Next Steps**\n\n1. **Additional Middleware**:\n   - Request body parsing\n   - CORS support\n   - Rate limiting\n\n2. **Testing**:\n   - Unit tests with Deno's testing framework\n   - Integration tests with request tracking\n\n3. **Monitoring**:\n   - Metrics collection\n   - Health check endpoints\n\n---\n\n## **Contributing**\n\nContributions are welcome! Please open an issue or submit a pull request.\n\n---\n\n## **License**\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n---\n\n## **Acknowledgments**\n\n- Built by DeepSeek \u0026 Cloude Sonet gently directed by yours truly.\n- Built with [Deno](https://deno.land/) and [Effection](https://frontside.com/effection/)\n- Inspired by functional programming principles and robust design patterns\n\n---\n 🚀\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrdjan%2Fdeno-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsrdjan%2Fdeno-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrdjan%2Fdeno-server/lists"}