Skip to main content

Deploy a static website with Wing

Platforms:

Example application that deploys a static website into the cloud

Deploy a static website with Wing

This example application deploys a static website to the cloud using a website resource. Additionally, it includes an API resource featuring a /hello-static POST endpoint.

The deployed website shows a button which makes a POST request to the API to increment a counter value.

INFO

The /hello-static POST endpoint in this example returns an inflight function. This is runtime code. When a request is received at this endpoint, the inflight code is executed.

1bring cloud;
2bring util;
3bring http;
4bring expect;
5
6let website = new cloud.Website(
7  path: "./static",
8);
9
10let api = new cloud.Api({
11  cors: true,
12  corsOptions: {
13    allowHeaders: ["*"],
14    allowMethods: [http.HttpMethod.POST],
15  },
16});
17website.addJson("config.json", { api: api.url });
18
19let counter = new cloud.Counter() as "website-counter";
20
21api.post("/hello-static", inflight (request) => {
22  return {
23    status: 200,
24    headers: {
25      "Content-Type" => "text/html",
26      "Access-Control-Allow-Origin" => "*",
27    },
28    body: "<div id=\"hello\" class=\"mt-4\">Hello {counter.inc()}</div>",
29  };
30});
31

Resources used in this example

  • Website - Deploy static websites into the cloud
  • API - Create APIs and deploy them into the cloud
  • Counter - Stateful container for one or more numbers in the cloud