context.info & context.env
The context.info object contains metadata about the current mim and the mimOE node it's running on. The context.env object contains environment variables passed at deployment time.
context.info
Read-only properties populated by the runtime.
Properties
| Property | Type | Description |
|---|---|---|
serviceType | string | The service type of the mim |
apiRoot | string | The API root path where the mim is mounted |
httpPort | string | The HTTP port that mimOE is listening on |
accountId | string | The account ID associated with the mimOE node |
nodeId | string | The unique identifier of the mimOE node |
serviceType
The service type identifier for this mim.
app.get('/info', (request, response) => {
response.end(JSON.stringify({
serviceType: context.info.serviceType
}));
});
apiRoot
The base path where this mim is mounted. Useful for constructing URLs to your own endpoints.
app.get('/info', (request, response) => {
var root = context.info.apiRoot;
// e.g., "/my-service/v1"
response.end(JSON.stringify({
apiRoot: root,
fullUrl: 'http://localhost:' + context.info.httpPort + root
}));
});
httpPort
The HTTP port that mimOE is listening on. Use this to call other mims or services on the same node.
app.get('/call-other', (request, response) => {
var port = context.info.httpPort;
context.http.request({
url: 'http://127.0.0.1:' + port + '/other-mim/v1/data',
success: function(result) {
response.end(result.data);
},
error: function(err) {
response.statusCode = 500;
response.end(err.message);
}
});
});
accountId
The account ID associated with this mimOE node. Useful for multi-tenant applications.
app.get('/info', (request, response) => {
response.end(JSON.stringify({
accountId: context.info.accountId
}));
});
nodeId
The unique identifier of this mimOE node. Useful for logging, debugging, and distributed systems.
app.get('/info', (request, response) => {
response.end(JSON.stringify({
nodeId: context.info.nodeId
}));
});
Full Example
app.get('/node-info', (request, response) => {
response.end(JSON.stringify({
serviceType: context.info.serviceType,
apiRoot: context.info.apiRoot,
httpPort: context.info.httpPort,
accountId: context.info.accountId,
nodeId: context.info.nodeId
}));
});
context.env
Environment variables passed to the mim at deployment time. Access variables using dot notation.
Usage
// Access environment variables
var apiKey = context.env.API_KEY;
var debugMode = context.env.DEBUG === 'true';
var maxRetries = parseInt(context.env.MAX_RETRIES || '3');
Setting Environment Variables
Environment variables are set when deploying the mim via the MCM API:
curl -X POST http://localhost:8083/mcm/v1/containers \
-H "Content-Type: application/json" \
-d '{
"name": "my-mim",
"image": "my-mim-v1",
"env": {
"API_KEY": "secret123",
"DEBUG": "true",
"MAX_RETRIES": "5",
"EXTERNAL_API_URL": "https://api.example.com"
}
}'