{"id":19839489,"url":"https://github.com/xeaone/server","last_synced_at":"2025-05-01T19:30:21.557Z","repository":{"id":37542506,"uuid":"475149011","full_name":"xeaone/server","owner":"xeaone","description":"X-Server a Deno server module with middleware","archived":false,"fork":false,"pushed_at":"2024-05-30T22:46:09.000Z","size":170,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-18T09:02:16.733Z","etag":null,"topics":["deno","framework","javascript","library","module","server","session","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xeaone.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2022-03-28T19:25:47.000Z","updated_at":"2024-07-24T06:02:39.000Z","dependencies_parsed_at":"2022-09-26T20:41:39.131Z","dependency_job_id":"2261d50e-69dd-4057-ab4e-afc1769cd621","html_url":"https://github.com/xeaone/server","commit_stats":{"total_commits":88,"total_committers":1,"mean_commits":88.0,"dds":0.0,"last_synced_commit":"42592c5992f1ea2d367e01e5231ade7a04d7da67"},"previous_names":[],"tags_count":57,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeaone%2Fserver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeaone%2Fserver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeaone%2Fserver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeaone%2Fserver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xeaone","download_url":"https://codeload.github.com/xeaone/server/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251932513,"owners_count":21667157,"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","framework","javascript","library","module","server","session","typescript"],"created_at":"2024-11-12T12:22:47.972Z","updated_at":"2025-05-01T19:30:21.093Z","avatar_url":"https://github.com/xeaone.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![deno module](https://shield.deno.dev/x/xserver)](https://deno.land/x/xserver)\n![deno compatibility](https://shield.deno.dev/deno/1.33.3)\n[![CodeQL](https://github.com/xeaone/server/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/xeaone/server/actions/workflows/codeql-analysis.yml)\n![GitHub](https://img.shields.io/github/license/xeaone/server)\n\n# X-Server\n\nDeno server module with built in middleware.\n\n## Use\n\nhttps://deno.land/x/xserver/src/mod.ts\n\n## Example\n\n```ts\nimport { Handler, Normalize, Router, Server } from 'https://deno.land/x/xserver/src/mod.ts';\n\nconst router = new Router();\nconst handler = new Handler();\nconst normalize = new Normalize();\n\nnormalize.any('/*', true);\n\nrouter.get('/*', (context) =\u003e context.html`\u003ch1\u003eHello World\u003c/h1\u003e`);\nrouter.post('/*', (context) =\u003e context.ok({ message: 'posted' }));\n\nhandler.add(normalize);\nhandler.add(router);\n\nServer((request) =\u003e handler.handle(request));\n```\n\n### Server\n\nWraps Deno.serve\n\n### Handler\n\nConstructor that stores the middleware/plugins/tools used on each request.\n\n```ts\nimport { Handler, Normalize, Server } from 'https://deno.land/x/xserver/src/mod.ts';\n\nconst handler = new Handler();\nconst normalize = new Normalize();\n\nhandler.add(normalize);\n\nServer((request) =\u003e handler.handle(request));\n```\n\n### Normalize\n\nConstructor Plugin that will remove `index.html`, `.html`, and `//` from the url then redirect. Optionally you can redirect `http` to `https` and `www` to `non-www`.\n\n```ts\nimport { Normalize } from 'https://deno.land/x/xserver/src/mod.ts';\nconst normalize = new Normalize();\nnormalize.www(true); // redirects www to non www\nnormalize.https(true); // redirects http to https\nnormalize.any('/*', true); // any method and any path Normalize\n```\n\n### Cors\n\nConstructor Plugin that will add cors header.\n\n```ts\nimport { Cors } from 'https://deno.land/x/xserver/src/mod.ts';\nconst cors = new Cors();\ncors.get('/foo', 'https://foo.com/'); // get method test path and CORS on only foo.com domain\ncors.any('/*', '*'); // any method any path and CORS on any domain\n```\n\n### Payload\n\nConstructor Plugin that will parse the request body.\n\n```ts\nimport { Payload } from 'https://deno.land/x/xserver/src/mod.ts';\nconst payload = new Payload();\npayload.parse('json'); // default is json\npayload.post('/*', true); // post method any path\n```\n\n### Router\n\nConstructor Plugin that will route request to a handle method.\n\n```ts\nimport { Router } from 'https://deno.land/x/xserver/src/mod.ts';\nconst router = new Router();\nrouter.post('/*', (context) =\u003e context.ok('hello world')); // post method any path\n```\n\n### File\n\nConstructor Plugin that will serve files. SPA mode will route all non existent files in the path folder to the `/index.html`.\n\n```ts\nimport { File } from 'https://deno.land/x/xserver/src/mod.ts';\nconst file = new File();\nfile.spa(true);\nfile.path('./web');\nfile.get('/*', true); // get method any path serve files from the ./web folder\n```\n\n### Session\n\nConstructor Plugin that will provide session using Secure Session Cookies https://tools.ietf.org/html/rfc6896.\n\n```ts\nimport { Session } from 'https://deno.land/x/xserver/src/mod.ts';\n\nconst sessions = new Map();\nconst session = new Session();\n\nsession.validate((context) =\u003e {\n    const { session } = context.tool.session.data;\n    // return a response to prevent access end exit the handler loop early\n    if (!sessions.has(session)) return context.unauthorized();\n});\n\nsession.secret('secret'); // unique secret\nsession.signature('signature'); // unique signature\n\nsession.any('/*', true); // any method and any path is protected\nsession.get('/*', false); // get method any path disable session protection\nsession.post('/sign-up', false); // post method specific path disable session protection\nsession.post('/sign-in', false); // post method specific path disable session protection\n```\n\n### Forwarded\n\nConstructor Plugin that will parse the `forwarded` header.\nThis is good for getting client/remote IP address behind a proxy/loadbalancer.\n\n```ts\nimport { Forwarded } from 'https://deno.land/x/xserver/src/mod.ts';\nimport { Handler, Server } from 'https://deno.land/x/xserver/src/mod.ts';\n\nconst forwarded = new Forwarded();\nconst handler = new Handler();\n\nforwarded.any('/*', true); // any method and any path parse forwarded header\n\nhandler.add(forwarded);\n\n/*\n    type ForwardedData = {\n        by: Array\u003cstring\u003e;\n        for: Array\u003cstring\u003e;\n        host: Array\u003cstring\u003e;\n        proto: Array\u003cstring\u003e;\n    };\n*/\nhandler.add(function (context) {\n    const { for: [client] } = context.tool.forwarded.data;\n    return context.ok(client);\n});\n\nServer((request) =\u003e handler.handle(request), { port: 8080 });\n```\n\n### Socket\n\nConstructor Plugin that will\n\n```ts\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxeaone%2Fserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxeaone%2Fserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxeaone%2Fserver/lists"}