我已经使用 Spring Boot 开发微服务有一段时间了,使用 feign 客户端、REST 模板和 AMPQ 代理在每个微服务之间建立通信。
现在,我正在学习 NestJs 及其微服务方法。我注意到 Nestjs 使用 TCP 作为默认传输层,这与 Spring Boot 的方式不同。
为什么nestjs更喜欢那些传输层(TCP,AMPQ)而不是HTTP?HTTP 不是 REST 微服务的传输协议吗?
来自 NestJs 文档:
“微服务本质上是一个使用与 HTTP 不同的传输层的应用程序”
在我的一个项目中,这很有效:
import cors from "cors";
server.use(cors());
Run Code Online (Sandbox Code Playgroud)
但目前,我的新项目中出现了这条可爱的打字稿警告消息:
No overload matches this call.
The last overload gave the following error.
Argument of type '(req: Request<never, never, never, never>, res: { statusCode?: number | undefined; setHeader(key: string, value: string): any; end(): any; }, next: (err?: any) => any) => void' is not assignable to parameter of type 'RequestHandlerParams<ParamsDictionary, any, any, ParsedQs>'.
Type '(req: Request<never, never, never, never>, res: { statusCode?: number | undefined; setHeader(key: string, value: string): any; end(): any; }, next: …Run Code Online (Sandbox Code Playgroud) 这就是我过去在通用模块中使用它的方式。
const debuger=require('debug')("namespace")
Run Code Online (Sandbox Code Playgroud)
我设置了一个环境变量DEBUG="namespace",当我启动应用程序时,我可以使用debugger.
但是我不知道如何将它与import/export陈述一起使用。
import debugger from "debug" // how can i pass () here
Run Code Online (Sandbox Code Playgroud) 我在运行时收到此错误anchor deploy:
Deploying workspace: http://127.0.0.1:8899
Upgrade authority: /home/<user>/.config/solana/id.json
Deploying program "faucet"...
Program path: /home/<user>/Workspace/<project_path>/target/deploy/xxx.so...
Error: RPC request error: cluster version query failed: error sending request for url (http://127.0.0.1:8899/): error trying to connect: tcp connect error: Connection refused (os error 111)
There was a problem deploying: Output { status: ExitStatus(ExitStatus(256)), stdout: "", stderr: "" }.
Run Code Online (Sandbox Code Playgroud)
在部署之前,我已经运行以下命令来更改本地的集群配置:
Deploying workspace: http://127.0.0.1:8899
Upgrade authority: /home/<user>/.config/solana/id.json
Deploying program "faucet"...
Program path: /home/<user>/Workspace/<project_path>/target/deploy/xxx.so...
Error: RPC request error: cluster version query failed: error sending request …Run Code Online (Sandbox Code Playgroud) 我试图遵循devto.io的教程并将交易发送到智能合约,我需要使用运行npx hardhat node命令时创建的帐户之一连接我的 MetaMask 钱包。为此,我打开 MetaMask 并将网络更新为 Localhost 8545,但 Metamask 未连接到它并显示如下屏幕截图所示的错误。

这是我卸载后的package.json sass node-sass,sass-loader因为我将节点版本从14更改为16,
{
"name": "our-awesome-project",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
"static": "NUXTJS_DEPLOY_TARGET=static NUXTJS_SSR=true nuxt generate",
"build-and-start": "NUXTJS_DEPLOY_TARGET=server NUXTJS_SSR=false nuxt build && NUXTJS_DEPLOY_TARGET=server NUXTJS_SSR=false nuxt start"
},
"husky": {
"hooks": {
"pre-commit": "cross-env PRE_COMMIT=true lint-staged -r"
}
},
"dependencies": {
"core-js": "^3.19.3",
"nuxt": "^2.15.8",
"nuxt-i18n": "^6.28.1",
"nuxt-purgecss": "^1.0.0",
"vue": "^2.6.14",
"vue-server-renderer": "^2.6.14",
"vue-template-compiler": "^2.6.14",
"webpack": "^4.46"
},
"devDependencies": {
"@nuxtjs/eslint-config": "^8.0.0",
"@nuxtjs/google-fonts": "^1.3.0",
"@nuxtjs/storybook": "^4.2.0", …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 useSelector 和 useDispatch 来更改 bulma 模型的状态
\n像这样
const isState = useSelector((state) => state.isActiveState)\nRun Code Online (Sandbox Code Playgroud)\nModel.js 是:
\nimport React from \'react\'\nimport "../CSS/Careers.css"\nimport { useSelector, useDispatch } from \'react-redux\';\nimport { stateCheck } from \'../Redux/ActiveState\'\n\nexport default function Modal() {\n\n const isState = useSelector((state) => state.isActiveState)\n \n \n\n const dispatch = useDispatch()\n\n \n return (\n <div>\n <div\n style={{ padding: "0rem 0.5rem 0rem" }}\n className={`modal ${isState}`} //this should change the state to \'is-active\'\n >\n <div onClick={() => dispatch(stateCheck())} className="modal-background"></div>\n <div style={{ borderRadius: …Run Code Online (Sandbox Code Playgroud) 我是 Next.js 的新手,正在将 JWT 授权令牌存储在客户端 React 上下文中,并希望将该令牌从客户端上下文“传递”到服务器组件,以便可以从服务器组件检索它通过headers()或cookies()函数。
我假设我需要在仅限客户端的代码上“设置”这些标头和 cookie,但是如何设置呢?
我更喜欢使用,headers()因为我可以控制何时/是否发送凭据;对于 cookie,我假设它总是随每个请求一起发送。
Next.js 13 的稳定版本有一个身份验证文档,但我已经从不使用getServerSideProps().
稳定的文档也提到了iron-session,我通过一个如何在 Next.js 13 中读取 cookie 的示例发现了这个问题,但它没有显示如何设置它。
tl;dr如何在客户端设置标头和 cookie,以便可以通过服务器组件中的headers()或函数读取它们?cookies()
authentication cookies http-headers server-side-rendering next.js
基本上我想用 Flask 和 LangChain 来实现这一点:https://www.youtube.com/watch?v =x8uwwLNxqis 。
我正在构建一个在后端使用 LangChain 的问答 Flask 应用程序,但我在传输来自 ChatGPT 的响应时遇到问题。我的链条看起来像这样:
chain = VectorDBQA.from_chain_type(llm=ChatOpenAI(model_name="gpt-3.5-turbo", streaming=True, chain_type="stuff", vectorstore=docsearch)
...
result = chain({"query": query})
output = result['result']
Run Code Online (Sandbox Code Playgroud)
Jinja 只是打印{{ output }},并且工作正常,但结果不会出现在网站中,直到整个响应完成。我想流式传输由 ChatGPT 生成的结果。
我尝试过使用stream_template,但它不起作用(它不传输结果,它只是立即打印完整的响应,尽管我可能做错了什么)。
我终于解决了:
我们目前正在使用 NextJS 13 开发一个应用程序next-auth,到目前为止一切都很好。我们的应用程序使用带有 a 的自定义登录页面,CredentialsProvider并且我们使用 next-auth 中间件来保护我们的路由。/login如果我们的用户已经通过身份验证,我们希望阻止他们访问。我们设法在客户端中实现这一点, useSession()但我们正在寻找一种方法来在中间件中实现此逻辑。next-auth使用当前的中间件实现可以实现这一点吗?以下是我们当前的中间件和路由配置。谢谢。
//middleware.ts
import withAuth from 'next-auth/middleware';
export default withAuth({
pages: {
signIn: `/login`,
},
});
Run Code Online (Sandbox Code Playgroud)
和
//route.ts
import NextAuth from 'next-auth';
import CredentialsProvider from 'next-auth/providers/credentials';
const handler = NextAuth({
pages: {
signIn: `/login`,
},
session: {
strategy: 'jwt',
},
providers: [
CredentialsProvider({
name: 'Credentials',
credentials: {
username: { label: 'Username', type: 'text' },
password: { label: 'Password', type: 'password' },
},
async authorize(credentials, …Run Code Online (Sandbox Code Playgroud) node.js ×4
blockchain ×2
next.js ×2
reactjs ×2
cookies ×1
cors ×1
debugging ×1
es6-modules ×1
ethereum ×1
express ×1
flask ×1
ganache ×1
http ×1
http-headers ×1
import ×1
langchain ×1
metamask ×1
middleware ×1
nestjs ×1
next-auth ×1
node-sass ×1
nuxt.js ×1
openai-api ×1
python ×1
react-redux ×1
redux ×1
sass ×1
solana ×1
solidity ×1
typescript ×1
webpack ×1