{"_id":"@apachedubbo/dubbo-next","name":"@apachedubbo/dubbo-next","dist-tags":{"alpha":"3.0.0-alpha","latest":"3.0.0-alpha"},"versions":{"3.0.0-alpha":{"name":"@apachedubbo/dubbo-next","version":"3.0.0-alpha","license":"Apache-2.0","repository":{"type":"git","url":"git+https://github.com/apache/dubbo-js.git","directory":"packages/dubbo-next"},"sideEffects":false,"scripts":{"clean":"rm -rf ./dist/cjs/* ./dist/esm/* ./dist/types/*","build":"npm run build:cjs && npm run build:esm+types","build:cjs":"tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'","build:esm+types":"tsc --project tsconfig.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/types"},"main":"./dist/cjs/index.js","type":"module","types":"./dist/types/index.d.ts","exports":{"types":"./dist/types/index.d.ts","import":"./dist/esm/index.js","require":"./dist/cjs/index.js"},"engines":{"node":">=16.0.0"},"dependencies":{"@apachedubbo/dubbo":"3.0.0-alpha","@apachedubbo/dubbo-node":"3.0.0-alpha"},"peerDependencies":{"@bufbuild/protobuf":"^1.2.1","next":"^13.2.4"},"gitHead":"dd9eba1b7b4c5d306fc8275537694cca02ad7975","description":"Dubbo is a family of libraries for building and consuming APIs on different languages and platforms, and [@apachedubbo/dubbo](https://www.npmjs.com/package/@apachedubbo/dubbo) brings type-safe APIs with Protobuf to TypeScript.","bugs":{"url":"https://github.com/apache/dubbo-js/issues"},"homepage":"https://github.com/apache/dubbo-js#readme","_id":"@apachedubbo/dubbo-next@3.0.0-alpha","_nodeVersion":"18.16.1","_npmVersion":"9.5.1","dist":{"integrity":"sha512-5AAiIP8P4eEZC6h42NMGAuZ2inkaEeoSGh7D/Cy53vBsOnuOV5fRfbAxPzvyRNCJ5y7eXGgkmGqSDsqGylUEBg==","shasum":"b4e43c7b49dc65222c2a4347395997efaff623e4","tarball":"https://registry.npmjs.org/@apachedubbo/dubbo-next/-/dubbo-next-3.0.0-alpha.tgz","fileCount":9,"unpackedSize":12372,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDp9QYqHnPOfpDefapSm8zhuccwPXvfoblwhJSgILShkAiEAnAGc1vEluMpnVmnYW4jMYc/9MM24unvf3xSENuZxUuI="}]},"_npmUser":{"name":"jianyi-gronk","email":"jianyi_gronk@163.com"},"directories":{},"maintainers":[{"name":"jianyi-gronk","email":"jianyi_gronk@163.com"},{"name":"apache-dubbo","email":"dubbo.alibaba@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/dubbo-next_3.0.0-alpha_1694061625335_0.7320350817259889"},"_hasShrinkwrap":false}},"time":{"created":"2023-09-07T04:40:25.226Z","3.0.0-alpha":"2023-09-07T04:40:25.506Z","modified":"2023-09-07T04:40:25.863Z"},"maintainers":[{"name":"jianyi-gronk","email":"jianyi_gronk@163.com"},{"name":"apache-dubbo","email":"dubbo.alibaba@gmail.com"}],"description":"Dubbo is a family of libraries for building and consuming APIs on different languages and platforms, and [@apachedubbo/dubbo](https://www.npmjs.com/package/@apachedubbo/dubbo) brings type-safe APIs with Protobuf to TypeScript.","homepage":"https://github.com/apache/dubbo-js#readme","repository":{"type":"git","url":"git+https://github.com/apache/dubbo-js.git","directory":"packages/dubbo-next"},"bugs":{"url":"https://github.com/apache/dubbo-js/issues"},"license":"Apache-2.0","readme":"# @apachedubbo/dubbo-next\n\nDubbo is a family of libraries for building and consuming APIs on different languages and platforms, and\n[@apachedubbo/dubbo](https://www.npmjs.com/package/@apachedubbo/dubbo) brings type-safe APIs with Protobuf to\nTypeScript.\n\n`@apachedubbo/dubbo-next` provides a plugin for [Next.js](https://nextjs.org/), \nthe React Framework for the Web.\n\n\n### nextJsApiRouter()\n\nProvide your Dubbo RPCs via Next.js API routes.  To enable Dubbo in Next.js, \nadd two files to your project:\n\n```diff\n.\n├── connect.ts\n└── pages\n    └── api\n        └── [[...connect]].ts\n```\n\n`connect.ts` is where you register your RPCs:\n\n```ts\n// connect.ts\nimport { DubboRouter } from \"@apachedubbo/dubbo\";\n\nexport default function(router: DubboRouter) {\n  // implement rpc Say(SayRequest) returns (SayResponse)\n  router.rpc(ElizaService, ElizaService.methods.say, async (req) => ({\n    sentence: `you said: ${req.sentence}`,\n  }));\n}\n```\n\n`pages/api/[[..connect]].ts` is a Next.js [catch-all API route](https://nextjs.org/docs/routing/dynamic-routes#catch-all-routes): \n\n```ts\n// pages/api/[[..connect]].ts\nimport { nextJsApiRouter } from \"@apachedubbo/dubbo-next\";\nimport routes from \"../../connect\";\n\nconst {handler, config} = nextJsApiRouter({ routes });\nexport {handler as default, config};\n```\n\nWith that server running, you can make requests with any Dubbo or gRPC-Web client.\nNote that Next.js serves all your RPCs with the `/api` prefix.\n\n`curl` with the Dubbo protocol:\n\n```bash\ncurl \\\n    --header \"Content-Type: application/json\" \\\n    --data '{\"sentence\": \"I feel happy.\"}' \\\n    --http2-prior-knowledge \\\n    http://localhost:3000/api/buf.connect.demo.eliza.v1.ElizaService/Say\n```\n\nNode.js with the gRPC-web protocol (using a transport from [@apachedubbo/dubbo-node](https://www.npmjs.com/package/@apachedubbo/dubbo-node)):\n\n```ts\nimport { createPromiseClient } from \"@apachedubbo/dubbo\";\nimport { createGrpcWebTransport } from \"@apachedubbo/dubbo-node\";\nimport { ElizaService } from \"./gen/eliza_dubbo.js\";\n\nconst transport = createGrpcWebTransport({\n  baseUrl: \"http://localhost:3000/api\",\n  httpVersion: \"1.1\",\n});\n\nconst client = createPromiseClient(ElizaService, transport);\nconst { sentence } = await client.say({ sentence: \"I feel happy.\" });\nconsole.log(sentence) // you said: I feel happy.\n```\n\nA client for the web browser actually looks identical to this example - it would\nsimply use `createDubboTransport` from [@apachedubbo/dubbo-web](https://www.npmjs.com/package/@apachedubbo/dubbo-web)\ninstead.\n\nNote that support for gRPC is limited, since many gRPC clients require HTTP/2,\nand Express does not support the Node.js `http2` module.\n\n\n### Deploying to Vercel\n\nCurrently, `@apachedubbo/dubbo-next` does not support the Vercel Edge runtime.\nIt requires the Node.js server runtime, which is used by default when deploying\nto Vercel.  \n\n\n## Getting started\n\nTo get started with Dubbo, head over to the [docs](https://cn.dubbo.apache.org/zh-cn/overview/quickstart/)\nfor a tutorial, or take a look at [our example](https://github.com/apache/dubbo-js/tree/dubbo3/example/). \n","readmeFilename":"README.md"}