123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- import { serve } from "https://deno.land/std@0.185.0/http/server.ts";
- import init, {render, JsResponse} from "./pkg/deno_wasm.js";
- const handler = async (request: Request): Promise<Response> => {
- await init();
- let url = new URL(request.url);
- if (url.pathname === '/pkg/deno_wasm.js') {
- const file = await Deno.open("./pkg/deno_wasm.js", {read: true});
- const readableStream = file.readable;
- const response = new Response(readableStream, {
- headers: {
- 'content-type': 'text/javascript'
- }
- });
- return response;
- }
- if (url.pathname === '/pkg/deno_wasm_bg.wasm') {
- const file = await Deno.open("./pkg/deno_wasm_bg.wasm", {read: true});
- const readableStream = file.readable;
- const response = new Response(readableStream, {
- headers: {
- 'content-type': 'application/wasm'
- }
- });
- return response;
- }
- if (url.pathname === '/favicon.ico') {
- return new Response (null, {
- status: 404
- });
- }
- else {
- try {
- const response = await render(request);
- let body_response = response.get().body_response;
-
- return new Response(body_response.body, {
- status: body_response.status_code,
- headers: {
- "content-type": body_response.content_type
- }
- });
- } catch (e) {
- const body = `ERROR: ${e}`
- return new Response(body, {
- status: 500,
- headers: {
- "content-type": "text/html; charset=utf-8"
- }
- });
- }
- }
- }
- serve(handler, {port: 3000, host: "192.168.100.29"});
|