{"id":15043152,"url":"https://github.com/ktmud/http-proxy-middleware-secure-cookies","last_synced_at":"2025-06-12T02:02:22.244Z","repository":{"id":55134966,"uuid":"288582288","full_name":"ktmud/http-proxy-middleware-secure-cookies","owner":"ktmud","description":"Securely add auth cookies to your webpack-dev-server proxies.","archived":false,"fork":false,"pushed_at":"2021-01-07T22:36:35.000Z","size":155,"stargazers_count":10,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-14T21:12:51.333Z","etag":null,"topics":["proxy","webpack"],"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/ktmud.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}},"created_at":"2020-08-18T23:04:08.000Z","updated_at":"2024-06-16T02:47:52.000Z","dependencies_parsed_at":"2022-08-14T13:00:50.936Z","dependency_job_id":null,"html_url":"https://github.com/ktmud/http-proxy-middleware-secure-cookies","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktmud%2Fhttp-proxy-middleware-secure-cookies","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktmud%2Fhttp-proxy-middleware-secure-cookies/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktmud%2Fhttp-proxy-middleware-secure-cookies/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktmud%2Fhttp-proxy-middleware-secure-cookies/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ktmud","download_url":"https://codeload.github.com/ktmud/http-proxy-middleware-secure-cookies/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248961237,"owners_count":21189993,"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":["proxy","webpack"],"created_at":"2024-09-24T20:48:38.579Z","updated_at":"2025-04-14T21:12:58.643Z","avatar_url":"https://github.com/ktmud.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# http-proxy-middleware-secure-cookies\n\nSecurely make authenticated requests to a remote server inside Webpack Dev Server proxies.\n\nThis library helps you create an [http-proxy-middleware](https://www.npmjs.com/package/http-proxy-middleware) that securly makes proxy requests with cookies. It will prompt you to enter auth cookies at initial start or when authentication failed.\n\n## Problem Statement\n\nImagine you have an API backend and a totally separate frontend. The dev environment for the backend is very complex to setup so sometimes you'd prefer to let local frontend dev server make direct requests to the production services or some shared environment.\n\nNow the tricky thing is the production service may require authentication. You local proxy has to bear the authentication headers or cookies in order to make requests to the API service. This package allows you to more easily manage and securely store the credentials needed for making these requests.\n\n## Usage\n\nIn `webpack.config.js`, add `devServer` proxy rules like below:\n\n```ts\nconst { secureCookieProxy } = require('http-proxy-middleware-secure-cookies');\n\nmodule.exports = {\n  // ...\n  devServer: {\n    // ...\n    proxy: {\n      // use the default options to proxy /api/* to https://foo.example.com/api/*\n      '/api/*': secureCookieProxy('https://api.example.com'),\n\n      // different endpoints share the same account\n      '/proxy/fiz': secureCookieProxy({\n        target: 'https://bar.example.com',\n        keychainAccount: 'example.com',\n      });\n      '/proxy/buz': secureCookieProxy({\n        target: 'https://buz.example.com',\n        keychainAccount: 'example.com',\n      });\n  }\n}\n\nmodule.exports = config;\n```\n\nThis will automatically proxy local requests for `http://locahost:$PORT/proxy/*` to `https://proxy-target.example.com`. If the server returns a `401` HTTP status code, the dev server will automatically prompt you to enter a cookie string, store it in file system or the system keychain (when available), then use the cookies to authenticate future requests.\n\n### Secure Cookie Storage\n\nBy default, the package will try to install `node-keytar` to store the cookies in system keychain, if for some reason the installation failed (e.g., [libsecret](https://github.com/atom/node-keytar#on-linux) not pre-installed on Linux), we will fallback to using local files. By default the local file used is `${process.cwd()}/.proxy-cookies/[keychainAccount]`. You can change the storage directory with following code (not recommended):\n\n```js\nconst os = require('os');\nconst { setCookieDirectory } = require('http-proxy-middleware-secure-cookies/dist/storage');\n\n// change it to home directory so cookies can be shared across apps\nsetCookieDirectory(`${os.homedir()}/.proxy-cookies`);\n```\n\n## Options\n\nPass options via `secureCookieProxy(options)`.\n\n## License\n\nThe MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktmud%2Fhttp-proxy-middleware-secure-cookies","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fktmud%2Fhttp-proxy-middleware-secure-cookies","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktmud%2Fhttp-proxy-middleware-secure-cookies/lists"}