Laravel Forge JavaScript SDK

Sites

Sites

Create a site

Method

forge.sites.create(server_id, payload)

Usage

1const forge = new Forge('API_TOKEN');
2
3const 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

KeyDescription
domainThe domain of the new site.
project_typeThe type of project. Available types can be found below.
aliasesAn array of site aliases you would like to add.
directoryThe web directory. For Laravel applications this is /public, but other projects may live elsewhere.
isolatedWhether the PHP-FPM process should run under its own user account. Learn about Website Isolation here.
usernameThe new user that should be created if isolated is true.
databaseThe name of the database to be created. This is optional.

Available project types

KeyDescription
phpGeneral PHP/Laravel Application.
htmlStatic HTML site.
symfonySymfony Application.
symfony_devSymfony (Dev) Application
symfony_fourSymfony >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');
2
3const 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');
2
3const 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');
2
3const 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

KeyDescription
directoryThe web directory. For Laravel applications this is /public, but other projects may live elsewhere.
nameThe name of the new site.
aliasesAn array of site aliases you would like to add.
wildcardsWhether 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');
2
3await forge.sites.php(server_id, site_id, payload);

Payload

1{
2 version: 'php74'
3}

Available Versions

KeyDescription
php56PHP 5.6
php70PHP 7.0
php71PHP 7.1
php72PHP 7.2
php73PHP 7.3
php74PHP 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');
2
3const updatedSite = await forge.sites.alias(server_id, site_id, payload);

Payload

1{
2 aliases: [
3 'alias1.com',
4 'alias2.com'
5 ]
6}

Payload Parameters

KeyDescription
aliasesAn 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');
2
3await forge.sites.delete(server_id, site_id);

Load balancing

Method

forge.sites.getBalance(server_id, site_id)

Usage

1const forge = new Forge('API_TOKEN');
2
3const 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": 80
9 },
10 {
11 "server_id": 3,
12 "weight": 1,
13 "down": false,
14 "backup": true,
15 "port": 80
16 },
17 {
18 "server_id": 4,
19 "weight": 1,
20 "down": true,
21 "backup": false,
22 "port": 80
23 }
24 ]
25}

Update Load balancing

Method

forge.sites.balance(server_id, site_id, payload)

Usage

1const forge = new Forge('API_TOKEN');
2
3await forge.sites.balance(server_id, site_id, payload);

Payload

1{
2 servers: [
3 {
4 id: 2,
5 weight: 5
6 },
7 {
8 id: 3,
9 backup: true
10 },
11 {
12 id: 4,
13 down: true
14 }
15 ],
16 method: 'least_conn'
17}

Payload Parameters

KeyDescription
serversArray of servers to distribute traffic to.
methodThe type of load balancing to apply.

Load Balancing Methods

KeyDescription
round_robin defaultRequests are evenly distributed across servers.
least_connRequests are sent to the server with the least number of active connections.
ip_hashThe 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');
2
3const 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