{"id":20438363,"url":"https://github.com/huang2002/3h-serve","last_synced_at":"2025-10-10T04:03:32.920Z","repository":{"id":57093081,"uuid":"167695262","full_name":"huang2002/3h-serve","owner":"huang2002","description":"A simple but powerful server.","archived":false,"fork":false,"pushed_at":"2020-06-13T02:58:22.000Z","size":44,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-03T23:42:25.288Z","etag":null,"topics":["3h","cli","serve","server","spa"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/huang2002.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-26T14:03:04.000Z","updated_at":"2020-06-13T02:58:25.000Z","dependencies_parsed_at":"2022-08-22T21:40:46.700Z","dependency_job_id":null,"html_url":"https://github.com/huang2002/3h-serve","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/huang2002/3h-serve","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huang2002%2F3h-serve","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huang2002%2F3h-serve/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huang2002%2F3h-serve/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huang2002%2F3h-serve/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/huang2002","download_url":"https://codeload.github.com/huang2002/3h-serve/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huang2002%2F3h-serve/sbom","scorecard":{"id":471519,"data":{"date":"2025-08-11","repo":{"name":"github.com/huang2002/3h-serve","commit":"850a61f4805b03bb5c30b3bd9a447a11f084209b"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T14:00:10.990Z","repository_id":57093081,"created_at":"2025-08-19T14:00:10.990Z","updated_at":"2025-08-19T14:00:10.990Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279002604,"owners_count":26083427,"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","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["3h","cli","serve","server","spa"],"created_at":"2024-11-15T09:10:39.212Z","updated_at":"2025-10-10T04:03:32.885Z","avatar_url":"https://github.com/huang2002.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 3h-serve\n\n\u003e A simple but powerful server.\n\n## TOC\n\n- [Introduction](#introduction)\n- [Features](#features)\n- [Command Line Usage](#command-line-usage)\n- [Program Usage](#program-usage)\n\n## Introduction\n\n`3h-serve` is a simple but powerful server which is mainly used for testing.\n\nYou can run `npm i -g 3h-serve` to install it globally and check the help information by executing `3h-serve -h`.\n\n## Features\n\n### Serverless Functions\n\nServerless functions are supported out of the box.\n\nFor example, given a script file `/api/helloWorld.js`:\n\n```js\nmodule.exports = (request, response) =\u003e {\n    response.end('Hello, world!');\n};\n```\n\nBy running `3h-serve --serverless \"^/api/\"` in the root directory and visitting `localhost:8080/api/helloWorld` in your browser, you should get `Hello, world!` as the result.\n\nMore specifically speaking, a function exported from a file which matches the serverless pattern given in options will be invoked to handle the request. The file defining the serverless function should be like this:\n\n```js\n/**\n * @param {import('http').IncomingMessage} request The native request object\n * @param {import('http').ServerResponse} response The native response object\n * @param {import('3h-serve').lib} lib The lib object (See `Program Usage` section)\n * @param {object} options Options passed to current handler\n */\nmodule.exports = (request, response, lib, options) =\u003e {\n    // Do something with the request and respond to it...\n};\n```\n\n### SPA Home Page Routing\n\nRouting single page applications is also supported. That is, with this feature, given a home page named `200.html`(the name can be configured) in a directory, requests to files in the directory which are not present will be responded with that page.\n\n### Lucid Caching\n\n`3h-serve` has a built-in cache control system. With cache enabled, all responses will have the following cache control directive and an `ETag` identifier, which tells the browsers that they can store any assets for a year but they must validate cached assets before serving them:\n\n```txt\nCache-Control: public, max-age=31536000, no-cache\n```\n\nIn this way, all assets will be cached but no stale assets will be served.\n\n### Clean URLs\n\nClean URLs mean that you can visit `/baz/index.html` by requesting `/baz/index` or even `/baz`, which includes default page serving and default extension matching. (Default: `index.html` and `.html`)\n\n### Automatic Zipping\n\nWith zipping enabled, all responses will be zipped if corresponding clients claim support of it (by using request header `Accept-Encoding`). This includes `br`, `gzip` and `deflate` zipping support.\n\n### Custom Fallback Page\n\nYou can also customize the fallback page of your site by just simpling put a file named `404.html`(the name can be configured) in the root directory of your site.\n\n### Debug Logging\n\n`3h-serve` provides detailed debug logging so that you can see how requests are solved. To enable logging, set log level to `log` or `debug`. Setting it to `log` results in some brief request and response information, while setting it to `debug` will make routing processes logging also available.\n\n## Command Line Usage\n\n```txt\n3h-serve \u003croot\u003e [options]\n\n    \u003croot\u003e                        Serving root\n                                  Default: .\n\n    -a, --absolute                Indicate that the root path is absolute\n\n    -p, --port          \u003cport\u003e    The port to listen on\n                                  Default: 8080\n\n    --default-page      \u003cfile\u003e    The default page to serve\n                                  Default: index.html\n\n    --no-default-page             Disable default page\n\n    --default-ext       \u003cext\u003e     Default file extension\n                                  Default: .html\n\n    --no-default-ext              Disable default file extension\n\n    --spa               \u003cfile\u003e    SPA home page\n                                  Default: 200.html\n\n    --no-spa                      Disable SPA routing\n\n    --forbidden                   Forbidden URL pattern\n\n    --fallback-page     \u003cfile\u003e    Fallback page path\n                                  Default: 404.html\n\n    --no-fallback-page            Disable fallback page\n\n    -s, --serverless              Serverless file pattern\n\n    --serverless-ext    \u003cext\u003e     Default serverless file extension\n                                  Default: .js\n\n    --no-serverless-ext           Disable default serverless file extension\n\n    --no-cache                    Disable cache\n\n    --no-zip                      Disable zipping\n\n    -l, --log-level               Log level\n                                  Options: \"info\"(default), \"log\", \"debug\"\n\n    --silent                      Disable log\n\n    --time-format                 Time format\n                                  Default: [YYYY-MM-DD HH:mm:SS.sss]\n\n    -h, --help                    Show help information\n```\n\n## Program Usage\n\nThe exported APIs are listed here which can be accessed by installing `3h-serve` as a dependency and importing them from `3h-serve`. (Note that the `lib` object is also available as the third parameter of serverless functions.)\n\n```ts\n/**\n * @desc The default MIME type map\n */\nconst DEFAULT_TYPES: Map\u003cstring, string\u003e;\n\n/**\n * @typedef ServeOptions\n * @property {string} root The root directory (Default: .)\n * @property {number} port The port to use (Default: 8080)\n * @property {string} timeFormat Time format passing to `3h-log` (Default: [YYYY-MM-DD HH:mm:SS.sss])\n * @property {boolean} cache Whether to enable cache (Default: true)\n * @property {boolean} zip Whether to enable response zipping (Default: true)\n * @property {'info' | 'log' | 'debug'} logLevel Log level (Default: info)\n * @property {boolean} silent Whether to suppress any log (including basic info logging)\n * @property {string | null} separator The separator between logs (Default: ----------)\n * @property {Map\u003cstring, string\u003e} types The MINE type map (Default: DEFAULT_TYPES)\n * @property {RegExp | null} forbiddenPattern Pattern of forbidden URLs (Default: null)\n * @property {RegExp | null} serverlessPattern Pattern of serverless files (Default: null)\n * @property {string | null} serverlessExtension Default extension of serverless files (Default: .js)\n * @property {string | null} spaPage SPA home page (Default: 200.html)\n * @property {string | null} defaultPage The default page to serve (Default: index.html)\n * @property {string | null} defaultExtension The default extension to match (Default: .html)\n * @property {string | null} fallbackPage Fallback page (Default: 404.html)\n */\n\n/**\n * @desc Defaults for `serve`\n */\nconst DEFAULT_SERVE_OPTIONS: ServeOptions;\n\n/**\n * @desc Create a server that acts according to given options\n */\nfunction serve(options?: ServeOptions): Server;\n\n/**\n * @desc The lib object provides some useful functionalities for dealing with requests\n */\nnamespace lib {\n\n    /**\n     * @desc Merge the defaults and options\n     */\n    function merge\u003cT\u003e(defaults: T, options: Partial\u003cT\u003e): T;\n\n    /**\n     * @desc Tell whether the given path is a file\n     */\n    function isFile(path: string): boolean;\n\n    /**\n     * @typedef RouteOptions\n     * @property {string | null} spaPage SPA home page\n     * @property {string | null} defaultPage The default page to serve\n     * @property {string | null} defaultExtension The default extension to match\n     * @property {boolean} acceptServerless Whether serverless files are acceptable\n     * @property {string | null} serverlessExtension Default serverless file extension\n     * @property {Logger | null} logger The logger to use\n     */\n\n    /**\n     * @typedef RoutingResult\n     * @property {string} path The result path\n     * @property {boolean} serverless Whether the target is a serverless function\n     */\n\n    /**\n     * @desc Route the given path and returns the result\n     */\n    function route(path: string, options: RouteOptions): RoutingResult | null;\n\n    /**\n     * @desc Log the status code and its corresponding status phrase\n     */\n    function logStatus(logger: Logger, statusCode: number): void;\n\n\n    /**\n     * @desc End the response with the given code and logs it if logger is provided\n     */\n    function endWithCode(response: ServerResponse, code: number, logger?: Logger | null): void;\n\n    /**\n     * @typedef EndWithFileOptions\n     * @property {boolean} cache\n     * @property {boolean} zip\n     * @property {Map\u003cstring, string\u003e} types\n     * @property {Logger | null} logger The logger to use\n     */\n\n    /**\n     * @desc End the response with the file indicated by `path`\n     */\n    function endWithFile(\n        request: IncomingMessage,\n        response: ServerResponse,\n        path: string,\n        options: EndWithFileOptions\n    ): void;\n\n    /**\n     * @typedef SolveOptions\n     * @property {string} root The root path\n     * @property {boolean} cache Whether to enable cache\n     * @property {boolean} zip Whether to enable zipping\n     * @property {Map\u003cstring, string\u003e} types The MIME map to use\n     * @property {RegExp | null} forbiddenPattern Pattern of forbidden URLs\n     * @property {RegExp | null} serverlessPattern Pattern of serverless files\n     * @property {string | null} serverlessExtension Default extension of serverless files\n     * @property {string | null} spaPage SPA home page\n     * @property {string | null} defaultPage The default page to serve\n     * @property {string | null} defaultExtension The default extension to match\n     * @property {string | null} fallbackPage Fallback page\n     * @property {Logger | null} logger The logger to use\n     */\n\n    /**\n     * @desc Solve the request according to the given path\n     */\n    function solve(\n        request: IncomingMessage,\n        response: ServerResponse,\n        path: string,\n        options: SolveOptions\n    ): void;\n\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuang2002%2F3h-serve","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuang2002%2F3h-serve","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuang2002%2F3h-serve/lists"}