alephjs/aleph.js

Support Deno Deploy?

tatemz opened this issue ยท 7 comments

Aleph applications won't work in Deno Deploy, but it would be a great opportunity to be compatible.

denoland/deploy_feedback#98 (comment)

Here's an example of how I wrote a mod.ts to test out Deno Deploy:

import { resolve } from "https://deno.land/std@0.108.0/path/mod.ts";
import { Aleph } from "https://deno.land/x/aleph@v0.3.0-beta.18/server/aleph.ts";
import { serve } from "https://deno.land/x/aleph@v0.3.0-beta.18/server/mod.ts";
import { parsePortNumber } from "https://deno.land/x/aleph@v0.3.0-beta.18/commands/helper/flags.ts";
import log from "https://deno.land/x/aleph@v0.3.0-beta.18/shared/log.ts";
import { existsDir } from "https://deno.land/x/aleph@v0.3.0-beta.18/shared/fs.ts";

const workingDir = resolve(String("./src"));
if (!await existsDir(workingDir)) {
  log.fatal("No such directory:", workingDir);
}

const aleph = new Aleph(
  workingDir,
  "production",
  false,
);

const port = parsePortNumber("8080");
await serve({ aleph, port });
ije commented

since deno deploy doesn't support the full file system API, aleph's cache and build system can not work, i am trying to create fs interface system to support that in #374 , but a bit busy

Thanks for Aleph!


Here is my solution ๐Ÿ˜„

aleph build
  • commit dist/ to git

create main.js for deno deploy

import { serve } from 'https://deno.land/std@0.116.0/http/server.ts'
import * as path from 'https://deno.land/std/path/mod.ts'

const MIME = new Map([
  ['.css', 'text/css'],
  ['.html', 'text/html'],
  ['.js', 'application/javascript'],
])
console.log({ MIME })

const DIST = path.resolve('./dist/')
console.log({ DIST })

async function handleRequest(request) {
  let { pathname } = new URL(request.url)
  console.group(pathname)
  console.log({ pathname })
  pathname = path.normalize(pathname)
  if (pathname === '/') {
    pathname = '/index.html'
  }
  const filename = path.join(DIST, pathname)
  console.log({ filename })
  const ext = path.extname(filename)
  let mime = MIME.get(ext) || 'text/plain'
  console.log({ ext })
  console.groupEnd(pathname)

  let file
  try {
    file = await Deno.readFile(filename)
  } catch (_) {}
  let status
  if (file) {
    status = 200
  } else {
    status = 404
    mime = MIME.get('.html') || 'text/plain'
    file = `<html>
      <head>
        <!-- <link rel="stylesheet" href="style.css" /> -->
      </head>
      <body>
        <h1>404 not found</h1>
      </body>
    </html>`
  }
  console.log({ pathname, status, mime })
  return new Response(file, {
    headers: { 'content-type': mime },
    status: status,
  })
}

const addr = ':8000'
console.log(`Listening on http://localhost${addr}`)
await serve(handleRequest)
ije commented

i am redesigning the framework to support deno deploy, in fact it will support any edge worker for example cloudflear

Guess can be closed now ๐Ÿค“

ije commented

@CanRau now the problem is to support vercel ๐Ÿ™ˆ

Haha life ๐Ÿ˜…

hello there, any soluction to deploy aleph.js to deno deploy?