Laravel Forge JavaScript SDK
Sites
Sites
Create a site
Method
forge.sites.create(server_id, payload)
Usage
1const forge = new Forge('API_TOKEN');23const site = await forge.sites.create(server_id, payload);
Payload
1{2 domain: 'site.com',3 project_type: 'php',4 aliases: [5 'alias1.com',6 'alias2.com'7 ],8 directory: '/test',9 isolated: true,10 username: 'forge',11 database: 'site-com-db'12}
Payload Parmeters
Key | Description |
---|---|
domain | The domain of the new site. |
project_type | The type of project. Available types can be found below. |
aliases | An array of site aliases you would like to add. |
directory | The web directory. For Laravel applications this is /public , but other projects may live elsewhere. |
isolated | Whether the PHP-FPM process should run under its own user account. Learn about Website Isolation here. |
username | The new user that should be created if isolated is true . |
database | The name of the database to be created. This is optional. |
Available project types
Key | Description |
---|---|
php | General PHP/Laravel Application. |
html | Static HTML site. |
symfony | Symfony Application. |
symfony_dev | Symfony (Dev) Application |
symfony_four | Symfony >4.0 Application |
Example Response
1{2 "site": {3 "id": 2,4 "name": "site.com",5 "aliases": [6 "alias1.com",7 "alias2.com"8 ],9 "directory": "/test",10 "wildcards": false,11 "isolated": true,12 "username": "forge",13 "status": "installing",14 "repository": null,15 "repository_provider": null,16 "repository_branch": null,17 "repository_status": null,18 "quick_deploy": false,19 "project_type": "php",20 "app": null,21 "app_status": null,22 "slack_channel": null,23 "telegram_chat_id": null,24 "telegram_chat_title": null,25 "created_at": "2016-12-16 16:38:08",26 "deployment_url": "...",27 "tags": []28 }29}
List a servers sites
Method
forge.sites.list(server_id)
Usage
1const forge = new Forge('API_TOKEN');23const sites = await forge.sites.list(server_id);
Example Response
1{2 "sites": [3 {4 "id": 2,5 "name": "site.com",6 "username": "laravel",7 "directory": "/test",8 "wildcards": false,9 "status": "installing",10 "repository": null,11 "repository_provider": null,12 "repository_branch": null,13 "repository_status": null,14 "quick_deploy": false,15 "project_type": "php",16 "app": null,17 "app_status": null,18 "slack_channel": null,19 "telegram_chat_id": null,20 "telegram_chat_title": null,21 "deployment_url": "...",22 "created_at": "2016-12-16 16:38:08",23 "tags": []24 }25 ]26}
Get a site
Method
forge.sites.get(server_id, site_id)
Usage
1const forge = new Forge('API_TOKEN');23const site = await forge.sites.get(server_id, site_id);
Example Response
1{2 "site": {3 "id": 2,4 "name": "site.com",5 "aliases": [6 "alias1.com"7 ],8 "username": "laravel",9 "directory": "/test",10 "wildcards": false,11 "status": "installing",12 "repository": null,13 "repository_provider": null,14 "repository_branch": null,15 "repository_status": null,16 "quick_deploy": false,17 "project_type": "php",18 "app": null,19 "app_status": null,20 "slack_channel": null,21 "telegram_chat_id": null,22 "telegram_chat_title": null,23 "deployment_url": "...",24 "created_at": "2016-12-16 16:38:08",25 "tags": []26 }27}
Update a site
This method is used to update the "web directory", primary name, aliases or whether to use wildcard sub-domains for a given site.
Method
forge.sites.update(server_id, site_id, payload)
Usage
1const forge = new Forge('API_TOKEN');23const updatedSite = await forge.sites.update(server_id, site_id, payload);
Payload
1directory: '/some/path',2name: 'site-new-name.com',3aliases: [4 'alias1.com',5 'alias2.com'6],7wildcards: true
Payload Parameters
Key | Description |
---|---|
directory | The web directory. For Laravel applications this is /public , but other projects may live elsewhere. |
name | The name of the new site. |
aliases | An array of site aliases you would like to add. |
wildcards | Whether to use wildcard sub-domains or not. |
Example Response
1{2 "site": {3 "id": 2,4 "name": "site-new-name.com",5 "aliases": [6 "alias1.com",7 "alias2.com"8 ],9 "username": "laravel",10 "directory": "/some/path",11 "wildcards": false,12 "status": "installing",13 "repository": null,14 "repository_provider": null,15 "repository_branch": null,16 "repository_status": null,17 "quick_deploy": false,18 "project_type": "php",19 "app": null,20 "app_status": null,21 "slack_channel": null,22 "telegram_chat_id": null,23 "telegram_chat_title": null,24 "deployment_url": "...",25 "created_at": "2016-12-16 16:38:08",26 "tags": []27 }28}
Change site PHP version
Method
forge.sites.php(server_id, site_id, payload)
Usage
1const forge = new Forge('API_TOKEN');23await forge.sites.php(server_id, site_id, payload);
Payload
1{2 version: 'php74'3}
Available Versions
Key | Description |
---|---|
php56 | PHP 5.6 |
php70 | PHP 7.0 |
php71 | PHP 7.1 |
php72 | PHP 7.2 |
php73 | PHP 7.3 |
php74 | PHP 7.4 |
Add site aliases
Use this endpoint to add additional site aliases and keep the exiting ones.
Method
forge.sites.alias(server_id, site_id, payload)
Usage
1const forge = new Forge('API_TOKEN');23const updatedSite = await forge.sites.alias(server_id, site_id, payload);
Payload
1{2 aliases: [3 'alias1.com',4 'alias2.com'5 ]6}
Payload Parameters
Key | Description |
---|---|
aliases | An array of site aliases you would like to add. |
Example Response
1{2 "site": {3 "id": 2,4 "name": "site.com",5 "aliases": [6 "alias1.com",7 "alias2.com"8 ],9 "username": "laravel",10 "directory": "/",11 "wildcards": false,12 "status": "installing",13 "repository": null,14 "repository_provider": null,15 "repository_branch": null,16 "repository_status": null,17 "quick_deploy": false,18 "project_type": "php",19 "app": null,20 "app_status": null,21 "slack_channel": null,22 "telegram_chat_id": null,23 "telegram_chat_title": null,24 "deployment_url": "...",25 "created_at": "2016-12-16 16:38:08",26 "tags": []27 }28}
Delete a site
Method
forge.sites.delete(server_id, site_id)
Usage
1const forge = new Forge('API_TOKEN');23await forge.sites.delete(server_id, site_id);
Load balancing
Method
forge.sites.getBalance(server_id, site_id)
Usage
1const forge = new Forge('API_TOKEN');23const loadBalancers = await forge.sites.getBalance(server_id, site_id);
Example Response
1{2 "nodes": [3 {4 "server_id": 2,5 "weight": 5,6 "down": false,7 "backup": false,8 "port": 809 },10 {11 "server_id": 3,12 "weight": 1,13 "down": false,14 "backup": true,15 "port": 8016 },17 {18 "server_id": 4,19 "weight": 1,20 "down": true,21 "backup": false,22 "port": 8023 }24 ]25}
Update Load balancing
Method
forge.sites.balance(server_id, site_id, payload)
Usage
1const forge = new Forge('API_TOKEN');23await forge.sites.balance(server_id, site_id, payload);
Payload
1{2 servers: [3 {4 id: 2,5 weight: 56 },7 {8 id: 3,9 backup: true10 },11 {12 id: 4,13 down: true14 }15 ],16 method: 'least_conn'17}
Payload Parameters
Key | Description |
---|---|
servers | Array of servers to distribute traffic to. |
method | The type of load balancing to apply. |
Load Balancing Methods
Key | Description |
---|---|
round_robin default | Requests are evenly distributed across servers. |
least_conn | Requests are sent to the server with the least number of active connections. |
ip_hash | The server to which a request is sent is determined from the client IP address. |
Site log
Method
forge.sites.log(server_id, site_id)
Usage
1const forge = new Forge('API_TOKEN');23const siteLog = await forge.sites.log(server_id, site_id);
Example Response
1{2 "content": "[2020-08-18 10:32:56] local.INFO: Test \n"3}
Edit this page on GitHub