Skip to content

src/app.ts

37 lines · 1.4 KB · TypeScript
Raw
import { packageContext } from 'kody:runtime'

/**
 * Serves the game page when it's hosted as a Kody package app. The browser
 * client (`src/main.ts`) renders the game itself.
 */
export default {
  async fetch() {
    const assetBasePath = packageContext?.assetBasePath
    const clientModuleUrl = packageContext?.clientModuleUrl
    if (!assetBasePath || !clientModuleUrl) {
      return new Response('Pirate Shooter must run as a Kody package app.', { status: 500 })
    }

    return new Response(
      `<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover, user-scalable=no" />
    <meta name="theme-color" content="#04121d" />
    <meta name="mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
    <link rel="icon" type="image/svg+xml" href="${assetBasePath}/icon.svg" />
    <link rel="manifest" href="${assetBasePath}/manifest.webmanifest" />
    <link rel="stylesheet" href="${assetBasePath}/style.css" />
    <title>Pirate Side Scroller</title>
  </head>
  <body>
    <script type="module" src="${clientModuleUrl}"></script>
  </body>
</html>`,
      { headers: { 'content-type': 'text/html; charset=utf-8' } },
    )
  },
}