next.js adapterArgs.rawResponse.getHeaders不是函数

ntjbwcob  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(65)

我正在尝试使用以下命令将next13 route.ts与shopify节点API连接

export async function GET(request: Request, res:Response) {
  const { searchParams } = new URL(request.url);
  const shop = searchParams.get('shop') as string;
  const service = new ShopifyService();
  return service.shopify.auth.begin({
    shop: service.shopify.utils.sanitizeShop(searchParams.get('shop'), true),
    callbackPath: '/auth/callback',
    isOnline: false,
    rawRequest: request,
  });
}

其中shopifyService只是一个简单的类型脚本类

export class ShopifyService {
    public shop: string | undefined;
    public accessToken: string | undefined;
    public shopify : any;
    // private shopify;
    constructor() {
         this.shopify = shopifyApi({
             // The next 4 values are typically read from environment variables for added security
             apiKey: process.env.CLIENT_SECRET,
             apiSecretKey: process.env.CLIENT_ID!,
             scopes: process.env.SCOPES!.split(','),
             hostName: process.env.HOST!,
             apiVersion: ApiVersion.April22,
             isEmbeddedApp: true,
             
         });
      
    }
}

当我尝试从Shopify管理员访问我的应用程序时,它给了我以下错误:

- error TypeError: Cannot read properties of undefined (reading 'statusCode')
    at eval (webpack-internal:///(sc_server)/./node_modules/@shopify/shopify-api/adapters/node/adapter.js:25:49)
    at Generator.next (<anonymous>)
    at eval (webpack-internal:///(sc_server)/./node_modules/tslib/tslib.es6.js:177:71)
    at new Promise (<anonymous>)
    at Module.__awaiter (webpack-internal:///(sc_server)/./node_modules/tslib/tslib.es6.js:159:12)
    at nodeConvertIncomingResponse (webpack-internal:///(sc_server)/./node_modules/@shopify/shopify-api/adapters/node/adapter.js:23:20)
    at eval (webpack-internal:///(sc_server)/./node_modules/@shopify/shopify-api/lib/auth/oauth/oauth.js:42:79)
    at Generator.next (<anonymous>)
    at fulfilled (webpack-internal:///(sc_server)/./node_modules/tslib/tslib.es6.js:162:32)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

你知道我错过了什么吗?

svgewumm

svgewumm1#

您可以尝试使用不同的适配器,例如
import '@shopify/shopify-api/adapters/web-api';
Web-API适配器设置头属性。这在苗条的工作,但不确定下一步..
参见shopify-api docs

相关问题