Jerry's previous article SAP S/4HANA Cloud SDK introduced how to call SAP S/4HANA Cloud SDK in third-party applications to consume OData services of the S/4HANA system.
At the time, in my code, the URL pointing to the SAP API Business Hub Sandbox was hard-coded, which was not flexible enough. This article describes how to configure these endpoints through environment variables.
Create a new .env file in the project root directory with the following content:
destinations=[{"name": "sandbox",
"url": "https://sandbox.api.sap.com/s4hanacloud"}]
Execute the following command line:
npm install @nestjs/config
In order to load the environment variables defined in the .env file, we need to add the ConfigModule provided by the config package to the @Module definition of the application. Open app.module.ts and update it with the following code:
Source code:
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { BusinessPartnerController } from './business-partner.controller';
@Module({
imports: [ConfigModule.forRoot()],
controllers: [AppController, BusinessPartnerController],
providers: [AppService],
})
export class AppModule {}
Change the parameters of the execute method in the application code from hard-coded url to passing a Destination name maintained in the .env file.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。