Website
The cloud.Website
resource represents a static website that can be hosted in the cloud.
Websites are typically used to serve static content, such as HTML, CSS, and JavaScript files, which are updated whenever the application is redeployed.
Usage
Website
bring cloud;
let website = new cloud.Website(path: "./public");
Under ./public/index.html
<!DOCTYPE html>
<html>
Hello Winglang!!!
</html>
Webapp
An extended Web App example including static Website, API Gateway and a Redis database, can be found in this example project.
Target-specific details
Review the Website RFC for detailed information.
Pass variables to the website
You can pass dynamic variables from the main.w file to the website, and recuperate them by fetching the config.js file. // inside main.w
bring cloud;
let website = new cloud.Website(path: "./static");
let api = new cloud.Api();
website.addJson("config.json", { api: api.url });
inside ./static/index.html
<html lang="en">
<html>
<body>
...
<script>
// Fetch the config file and get the API URL
let ApiUrl;
fetch('/config.json')
.then(response => response.json())
.then(data => {
ApiUrl = data.api;
});
</script>
</body>
</html>
Simulator (sim
)
sim implementations of cloud.Website
is using nodejs express.
AWS (tf-aws
and awscdk
)
AWS implementations of cloud.Website
uses Amazon S3 & Amazon CloudFront.
Azure (tf-azure
)
🚧 Not supported yet (tracking issue: #1295)
GCP (tf-gcp
)
🚧 Not supported yet (tracking issue: #1296)
API Reference
Website
- Implements: IWebsite
A cloud static website.
Initializers
bring cloud;
new cloud.Website(props: WebsiteProps);
Name | Type | Description |
---|---|---|
|
| No description. |
props
Required
- Type: WebsiteProps
Methods
Preflight Methods
Name | Description |
---|---|
| Add a file to the website during deployment. |
| Add a JSON file with custom values during the website's deployment. |
addFile
addFile(path: str, data: str, options?: AddFileOptions): str
Add a file to the website during deployment.
If the path conflicts with file path from the website's static assets, an error will be thrown.
path
Required
- Type: str
the file path it will be uploaded as.
data
Required
- Type: str
the data to write to the file.
options
Optional
- Type: AddFileOptions
configure the file's options.
addJson
addJson(path: str, data: Json): str
Add a JSON file with custom values during the website's deployment.
If the path conflicts with file path from the website's static assets, an error will be thrown.
path
Required
- Type: str
the file path it will be uploaded as.
data
Required
- Type: Json
the data to write to the file.
Static Functions
Name | Description |
---|---|
| A hook called by the Wing compiler once for each inflight host that needs to use this type inflight. |
| Generates an asynchronous JavaScript statement which can be used to create an inflight client for a resource. |
onLiftType
bring cloud;
cloud.Website.onLiftType(host: IInflightHost, ops: MutArray<str>);
A hook called by the Wing compiler once for each inflight host that needs to use this type inflight.
The list of requested inflight methods
needed by the inflight host are given by ops
.
This method is commonly used for adding permissions, environment variables, or other capabilities to the inflight host.
host
Required
- Type: IInflightHost
ops
Required
- Type: MutArray<str>
toInflight
bring cloud;
cloud.Website.toInflight(obj: IResource);
Generates an asynchronous JavaScript statement which can be used to create an inflight client for a resource.
NOTE: This statement must be executed within an async context.
obj
Required
- Type: IResource
Properties
Name | Type | Description |
---|---|---|
| constructs.Node | The tree node. |
| str | Absolute local path to the website's static files. |
| str | The website's url. |
node
Required
node: Node;
- Type: constructs.Node
The tree node.
path
Required
path: str;
- Type: str
Absolute local path to the website's static files.
url
Required
url: str;
- Type: str
The website's url.
Structs
AddFileOptions
Options for adding a file with custom value during the website's deployment.
Initializer
bring cloud;
let AddFileOptions = cloud.AddFileOptions{ ... };
Properties
Name | Type | Description |
---|---|---|
| str | File's content type. |
contentType
Optional
contentType: str;
- Type: str
File's content type.
WebsiteDomainOptions
Options for Website
.
Initializer
bring cloud;
let WebsiteDomainOptions = cloud.WebsiteDomainOptions{ ... };
Properties
Name | Type | Description |
---|---|---|
|
| The website's custom domain object. |
domain
Optional
domain: Domain;
- Type: Domain
- Default: undefined
The website's custom domain object.
WebsiteOptions
Basic options for Website
.
Initializer
bring cloud;
let WebsiteOptions = cloud.WebsiteOptions{ ... };
Properties
Name | Type | Description |
---|---|---|
| str | Local path to the website's static files, relative to the Wing source file or absolute. |
| str | Name of the error document for the website. |
path
Required
path: str;
- Type: str
Local path to the website's static files, relative to the Wing source file or absolute.
Example
"./dist"
errorDocument
Optional
errorDocument: str;
- Type: str
- Default: undefined
Name of the error document for the website.
Example
"404.html"
WebsiteProps
Options for Website
.
Initializer
bring cloud;
let WebsiteProps = cloud.WebsiteProps{ ... };
Properties
Name | Type | Description |
---|---|---|
| str | Local path to the website's static files, relative to the Wing source file or absolute. |
| str | Name of the error document for the website. |
|
| The website's custom domain object. |
path
Required
path: str;
- Type: str
Local path to the website's static files, relative to the Wing source file or absolute.
Example
"./dist"
errorDocument
Optional
errorDocument: str;
- Type: str
- Default: undefined
Name of the error document for the website.
Example
"404.html"
domain
Optional
domain: Domain;
- Type: Domain
- Default: undefined
The website's custom domain object.
Protocols
IWebsite
Base interface for a website.
Properties
Name | Type | Description |
---|---|---|
| str | The website URL. |
url
Required
url: str;
- Type: str
The website URL.