日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Angular 服务器端渲染的一个错误消息 - No provider for InjectionToken REQUEST

發(fā)布時間:2023/12/19 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Angular 服务器端渲染的一个错误消息 - No provider for InjectionToken REQUEST 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

錯誤消息:

NullInjectorError: R3InjectorError(AppServerModule)

WindowRef -> InjectionToken SERVER_REQUEST_URL -> InjectionToken SERVER_REQUEST_URL -> InjectionToken SERVER_REQUEST_URL -> InjectionToken REQUEST]:

NullInjectorError: No provider for InjectionToken REQUEST!

Angular universal engine 的文檔:

https://github.com/angular/universal/tree/master/modules/express-engine

服務(wù)器端的 HTTP request 調(diào)用,通過 Injection token 注入到 SSR Application 里:

import { Request } from 'express'; import { REQUEST } from '@nguniversal/express-engine/tokens';@Injectable() export class RequestService {constructor(@Inject(REQUEST) private request: Request) {} }

這個 token 在客戶端環(huán)境下不可用。

相關(guān)錯誤:https://github.com/angular/universal-starter/issues/423

https://gitter.im/angular/universal/archives/2018/06/17

REQUEST and RESPONSE won’t exist when you run in the browser context, even when you are running the SSR server
Use @Optional and take care to check whether you’ve got it, and consider using isServerPlatform to detect when you are running on the server side

在瀏覽器上下文環(huán)境運(yùn)行時,REQUEST 和 RESPONSE 不可用。使用 @Optional 來避免 NullInjectorError 錯誤,以及使用 isServerPlatform 檢測當(dāng)前的運(yùn)行環(huán)境。

相關(guān) issue:https://github.com/SAP/spartacus/issues/11016

The SERVER_REQUEST_ORIGIN and SERVER_REQUEST_URL should not be provided in CSR by design.

SERVER_REQUEST_ORIGIN 在文件 ssr-providers.ts 里提供實(shí)現(xiàn):

總結(jié)

以上是生活随笔為你收集整理的Angular 服务器端渲染的一个错误消息 - No provider for InjectionToken REQUEST的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。