头图

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.

official website link

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.


注销
1k 声望1.6k 粉丝

invalid