-
Notifications
You must be signed in to change notification settings - Fork 7
C. SOA Services
In this section, you will learn how to create and configure a SOA Service Class.
A SOA Application Class is simply a container that will extend functionality from the core Application
, in here you install modules that will be loaded within that application.
You won't be required to add any functionality or logic within this class, is more likely a configuration class where as stated before you will install modules.
import { Application, SOAService } from '@onixjs/core';
import { MainModule } from './modules/main.module';
@SOAService({
modules: [MainModule]
})
export class MySOAService extends Application {}
The previous example does install a MainModule
that you might create within the ./modules
directory, but there are alternative options depending on the final purpose of your service.
SOA Services can either work as API RPC/Stream Services, API REST Services or Rendering Services.
When creating SOA Services as API RPC/Stream Services, normally you will disable the network in order to allow the OnixJS Host to handle client requests and route those requests to each of your SOA Services using STD IO Streams.
onixjs.config.json
{
"apps": [
"[email protected]:disabled",
]
}
Since you are able to also create REST Services, these services won't be routed by the OnixJS Host. Instead, you will directly call those REST Endpoints using HTTP Calls.
Therefore you actually will be required to expose those services by setting up a PORT as follows.
onixjs.config.json
{
"apps": [
"[email protected]:8000",
]
}
Alternatively, you can use your SOA Services as rendering services, which means that you actually are able not only to build API related services, but you are able to serve static files. Of course, that will also require enabling the network by setting up a network port.
onixjs.config.json
{
"apps": [
"[email protected]:8000",
]
}
According to the nature of your service, you will be required choose between the options above, but if you find useful to serve static files using your SOA Service, you will also be required to define the current working directory (CWD) since the final code won't be executed within the source of TypeScript files, within some static files directory.
import { Application, SOAService } from '@onixjs/core';
import { MainModule } from './modules/main.module';
import * as path from 'path';
@SOAService({
cwd: path.join(process.cwd(), 'some', 'static', 'path'),
modules: [MainModule]
})
export class MainApp extends Application {}