-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored compute script to edge scripting scripts
- Loading branch information
Showing
12 changed files
with
425 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,113 @@ $edgeScriptingApi->getCode( | |
$edgeScriptingApi->setCode( | ||
id: 1, | ||
body: [ | ||
'Code' => "export default function handleQuery(event) {\n console.log(\"Hello world!\")\n return new TxtRecord(\"Hello world!\");\n}", | ||
'Code' => "import * as BunnySDK from \"https://esm.sh/@bunny.net/[email protected]\";\n\n/**\n * Returns an HTTP response.\n * @param {Request} request - The Fetch API Request object.\n * @return {Response} The HTTP response or string.\n */\nBunnySDK.net.http.serve(async (request: Request): Response | Promise<Response> => {\n const url = new URL(request.url);\n return new Response(\"Hello from \" + url.pathname);\n});\n", | ||
], | ||
); | ||
``` | ||
|
||
### Edge Script | ||
|
||
#### [List Edge Scripts](https://docs.bunny.net/reference/listedgescriptsendpoint_listedgescriptsbyaccount) | ||
|
||
```php | ||
$edgeScriptingApi->listEdgeScripts( | ||
query: [ | ||
'page' => 1, | ||
'perPage' => 1000, | ||
'search' => 'Test', | ||
'includeLinkedPullzones' => false, | ||
'integrationId' => 1234, | ||
], | ||
); | ||
``` | ||
|
||
#### [Add Edge Script](https://docs.bunny.net/reference/createedgescriptendpoint_addscript) | ||
|
||
```php | ||
$edgeScriptingApi->addEdgeScript( | ||
body: [ | ||
'Name' => 'Test Script Modified', | ||
'Code' => "import * as BunnySDK from \"https://esm.sh/@bunny.net/[email protected]\";\n\n/**\n * Returns an HTTP response.\n * @param {Request} request - The Fetch API Request object.\n * @return {Response} The HTTP response or string.\n */\nBunnySDK.net.http.serve(async (request: Request): Response | Promise<Response> => {\n const url = new URL(request.url);\n return new Response(\"Hello from \" + url.pathname);\n});\n", | ||
'ScriptType' => 1, | ||
'CreateLinkedPullZone' => true, | ||
'LinkedPullZoneName' => 'MyPullZone', | ||
'Integration' => [ | ||
'IntegrationId' => 1234, | ||
'RepositorySettings' => [ | ||
'Id' => 1234, | ||
'Name' => 'Test Repo', | ||
'Private' => true, | ||
'TemplateUrl' => 'https://example.com', | ||
], | ||
'DeployConfiguration' => [ | ||
'Branch' => 1234, | ||
'InstallCommand' => 'Test Repo', | ||
'BuildCommand' => 'true', | ||
'EntryFile' => 'test.js', | ||
'CreateWorkflow' => false, | ||
], | ||
], | ||
], | ||
); | ||
``` | ||
|
||
!!! note | ||
|
||
- The key `ScriptType` has the following possible values: | ||
- `0` = DNS (DNS scripts) | ||
- `1` = Standalone (Standalone scripts are ideal for a wide range of applications, such as building RESTful APIs, delivering UI applications, and processing data at the edge.) | ||
- `2` = Middleware (Middleware scripts common use cases include user authentication, error handling, logging, security enhancements, A/B testing, HTML manipulation, and more.) | ||
|
||
|
||
#### [Get Edge Script](https://docs.bunny.net/reference/getedgescriptbyidendpoint_getedgescriptbyid) | ||
|
||
```php | ||
$edgeScriptingApi->getEdgeScript( | ||
id: 1, | ||
); | ||
``` | ||
|
||
#### [Get Edge Script Statistics](https://docs.bunny.net/reference/edgescriptstatisticsendpoint_getedgescriptstatisticsendpoint) | ||
|
||
```php | ||
$edgeScriptingApi->getEdgeScriptStatistics( | ||
id: 1, | ||
query: [ | ||
'dateFrom' => 'm-d-Y', | ||
'dateTo' => 'm-d-Y', | ||
'loadLatest' => false, | ||
'hourly' => false, | ||
], | ||
); | ||
``` | ||
|
||
#### [Update Edge Script](https://docs.bunny.net/reference/updateedgescriptendpoint_update) | ||
|
||
```php | ||
$edgeScriptingApi->updateEdgeScript( | ||
id: 1, | ||
body: [ | ||
'Name' => 'Test Script', | ||
'ScriptType' => 1, | ||
], | ||
); | ||
``` | ||
|
||
!!! note | ||
|
||
- The key `ScriptType` has the following possible values: | ||
- `0` = DNS (DNS scripts) | ||
- `1` = Standalone (Standalone scripts are ideal for a wide range of applications, such as building RESTful APIs, delivering UI applications, and processing data at the edge.) | ||
- `2` = Middleware (Middleware scripts common use cases include user authentication, error handling, logging, security enhancements, A/B testing, HTML manipulation, and more.) | ||
|
||
#### [Delete Edge Script](https://docs.bunny.net/reference/deleteedgescriptendpoint_delete) | ||
|
||
```php | ||
$edgeScriptingApi->deleteEdgeScript( | ||
id: 1, | ||
query: [ | ||
'deleteLinkedPullZones' => false, | ||
], | ||
); | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.