HTTP 엔드포인트 구성 파일
참고
이 페이지에서는 레거시 구성 파일 형식에 대해 설명합니다. 이 정보는 더 이상 사용되지 않는 realm-cli
을 사용하는 경우에만 사용해야 합니다.
App Services CLI로 가져오거나 UI에서 내보내는 모든 구성 파일은 최신 구성 버전을 사용합니다. 현재 구성 파일 형식에 대한 자세한 내용은 앱 구성을 참조하세요.
app/ └── http_endpoints/ ├── config.json ├── data_api_config.json └── [Deprecated] <Service Name>/ ├── config.json ├── rules/ │ └── <Rule Name>.json └── incoming_webhooks/ └── <Webhook Name>/ ├── config.json └── source.js
사용자 지정 HTTPS 엔드포인트 구성
앱의 모든 사용자 지정 HTTPS 엔드포인트 에 대한 구성을 http_endpoints/config.json
의 배열로 정의합니다.
[ { "route": "<Endpoint route name>", "http_method": "<HTTP method>", "function_name": "<Endpoint function name", "validation_method": "<Authorization scheme>", "secret_name": "<Validation Secret Name>", "respond_result": <boolean>, "fetch_custom_user_data": <boolean>, "create_user_on_auth": <boolean>, "disabled": <boolean> } ]
필드 | 설명 |
---|---|
route string | 엔드포인트 경로입니다. |
http_method string | HTTP 메서드 의 유형 엔드포인트가 처리합니다. 단일 엔드포인트로 모든 메서드를 처리하다 하려면 다음 중 하나입니다.
|
function_name string | 엔드포인트와 연결된 함수 의 이름입니다. 함수는 엔드포인트 함수 서명을 사용해야 합니다. |
validation_method string | 들어오는 요청의 유효성을 검사하는 데 사용되는 엔드포인트 권한 부여 체계 입니다. 다음 중 하나입니다.
|
secret_name string | 문자열이 포함된 시크릿 의 이름입니다. |
respond_result boolean |
|
fetch_custom_user_data boolean |
|
create_user_on_auth boolean |
이 설정은 사용자 지정 JSON web token 인증 제공자를 통해 외부 인증 시스템과 통합되는 앱에 유용합니다. 요청에 등록된 사용자와 일치하지 않는 외부 시스템의 유효한 JSON web token이 포함된 경우 JSON web token을 ID로 사용하여 새 사용자가 생성됩니다. |
disabled boolean | 엔드포인트를 활성화( |
데이터 API 구성
http_endpoints/data_api_config.json
에서 앱에서 생성된 데이터 API 엔드포인트 에 대한 구성을 정의합니다.
{ "disabled": <boolean>, "versions": ["v1"], "return_type": "EJSON" | "JSON", "create_user_on_auth": <boolean>, "run_as_system": <boolean>, "run_as_user_id": "<User Account ID>", "run_as_user_id_script_source": "<Function Source Code>" }
필드 | 설명 |
---|---|
disabled boolean |
|
versions string[] | 앱이 지원하는 데이터 API 버전 목록입니다. 목록에는 가능한 모든 버전의 하위 집합이 포함될 수 있지만 버전은 오름차순으로 나열해야 합니다. 가장 최근 버전 이외의 버전을 활성화할 수는 없지만 여기에 나열된 이전에 활성화한 버전은 계속 작동합니다. 사용 가능한 버전:
|
return_type string | HTTPS 응답 본문에서 엔드포인트가 반환한 데이터에 사용할 데이터 형식입니다. 다음 중 하나입니다.
|
create_user_on_auth boolean |
이 설정은 사용자 지정 JSON web token 인증 제공자를 통해 외부 인증 시스템과 통합되는 앱에 유용합니다. 요청에 등록된 사용자와 일치하지 않는 외부 시스템의 유효한 JSON web token이 포함된 경우 JSON web token을 ID로 사용하여 새 사용자가 생성됩니다. |
run_as_user_id string | 애플리케이션 사용자의 계정 ID. 정의된 경우 엔드포인트는 항상 지정된 사용자로 실행됩니다.
|
run_as_user_id_script_source string | 애플리케이션 사용자의 계정 ID를 반환하는 함수 에 대한 문자열화된 소스 코드입니다. 정의된 경우 엔드포인트는 모든 요청에서 함수를 실행하고 함수에서 반환된 ID를 가진 사용자로 실행됩니다.
|
[사용 중단됨] HTTP 서비스 구성
더 이상 사용되지 않는 레거시 HTTP 서비스는 /http_endpoints
내의 명명된 서비스로 그룹화됩니다.
{ "name": "<Service Name>", "type": "http", "config": {} }
필드 | 설명 |
---|---|
name String | HTTP 엔드포인트 서비스의 이름입니다. 이 이름은 앱의 모든 HTTP 엔드포인트 서비스 중에서 고유해야 하며 해당 디렉토리의 이름과 일치해야 합니다. |
type String | HTTP 엔드포인트의 경우 이 값은 항상 |
config String | 서비스에 대한 추가 구성 옵션입니다. HTTP Endpoints에는 현재 추가 구성 옵션이 없습니다. |
[사용 중단됨] 서비스 작업 규칙
서비스의 rules/
하위 디렉토리에서 서비스 작업 규칙 을 정의합니다. 각 규칙은 규칙과 이름이 같은 자체 .json
구성 파일에 매핑됩니다.
{ "name": "<Rule Name>", "actions": ["<Service Action Name>"], "when": { <JSON Rule Expression> } }
[사용 중단됨] 수신 Webhooks
구성
{ "name": "<Webhook Name>", "can_evaluate": { <JSON Expression> }, "run_as_authed_user": <Boolean>, "run_as_user_id": "<App Services User ID>", "run_as_user_id_script_source": "<Function Source Code>", "fetch_custom_user_data": <Boolean>, "create_user_on_auth": <Boolean>, "respond_result": <Boolean>, "options": { "httpMethod": "<HTTP Method>", "validationMethod": "<Webhook Validation Method>", "secret": "<Webhook Secret>" } }
필드 | 설명 | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
name String | 웹훅의 이름입니다. 이 이름은 HTTP 엔드포인트 서비스의 모든 웹훅 간에 고유해야 하며 해당 디렉토리의 이름과 일치해야 합니다. | |||||||||||||
can_evaluate JSON Expression (default: true ) | 웹훅 실행이 허용된 경우 | |||||||||||||
disable_arg_logs Boolean |
| |||||||||||||
run_as_authed_user Boolean |
팁자격 증명을 지정하는 방법의 예는 서비스 웹훅 구성 [사용 중단됨]을 참조하세요. | |||||||||||||
run_as_user_id String | 함수가 항상 실행되는 App Services 사용자 의 고유 ID입니다. | |||||||||||||
run_as_user_id_script_source String | 웹훅이 호출될 때마다 실행되고 함수 가 실행되는 App Services 사용자 의 고유 ID를 반환하는 문자열화된 함수입니다. | |||||||||||||
respond_result Boolean |
| |||||||||||||
fetch_custom_user_data Boolean |
이 옵션은 | |||||||||||||
create_user_on_auth Boolean |
이 옵션은 | |||||||||||||
options Document | 웹훅에 대한 구성 옵션이 포함된 문서입니다.
|
소스 코드
웹훅 디렉토리 내의 source.js
파일에 웹훅 함수의 소스 코드를 정의합니다. 각 파일은 요청이 웹훅을 호출할 때마다 실행되는 메인 함수를 내보내야 합니다.
exports = async function (payload, response) { // Convert the webhook body from BSON to an EJSON object const body = EJSON.parse(payload.body.text()); // Execute application logic, such as working with MongoDB if (body.someField) { const mdb = context.services.get("mongodb-atlas"); const requests = mdb.db("demo").collection("requests"); const { insertedId } = await requests.insertOne({ someField: body.someField, }); // Respond with an affirmative result response.setStatusCode(200); response.setBody(`Successfully saved "someField" with _id: ${insertedId}.`); } else { // Respond with a malformed request error response.setStatusCode(400); response.setBody(`Could not find "someField" in the webhook request body.`); } // This return value does nothing because we already modified the response object. // If you do not modify the response object and you enable *Respond with Result*, // App Services will include this return value as the response body. return { msg: "finished!" }; };