aleph.js: Request error with Oak

I’m trying to implement Aleph into an existing Oak server but am blocked by react.development.js requests coming back invalid.

import { Application as Oak } from "https://deno.land/x/oak/mod.ts";
import { Application, Server } from "https://deno.land/x/aleph/server/mod.ts";
import { localProxy } from "https://deno.land/x/aleph/server/localproxy.ts";
import { serve } from "https://deno.land/std@0.91.0/http/server.ts";

localProxy(8080);

const port = 1337;
const hostname = "localhost";
const oak = new Oak();
const app = new Application(".", "development", false);
const server = new Server(app);

oak.use(async (ctx) => {
  await server.handle(ctx.request.serverRequest as any);
});
await oak.listen({ port });

//let s = serve({ port, hostname });
//for await (const r of s) {
//  server.handle(r as any);
//}

image

Looks like the full file isn’t being returned for some reason. Oak on top, std on bottom image

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (11 by maintainers)

Most upvoted comments

@aadamsx The /api directory is for serverless functions, like NextJS

@aadamsx So, we are probably going to support having Aleph for full stack - but it is much more performant and organized to seperate the frontend and the backend. That allows you to modify them seperately without getting bogged down on tooling that combines then and since the frontend would either use static files or serverless functions which are fast, the frontend would be fast and not limited by the overhead of serving static files with a normal server.

@KotlinIsland thanks, i think we should provide a oka middleware directly to handle this, i will look into it

I just figured out how to fix this ctx.respond = false; must be specified from Oak.

oak.use((ctx) => {
  alephServer.handle(ctx.request.serverRequest as any);
  ctx.respond = false;
});