Questions tagged [oak]

For questions about Oak, the middleware framework for Deno's net server

77 questions
9
votes
1 answer

How to strongly type the Oak context state object in deno?

I want to strongly type the context.state object provided by oak in deno. I have already seen approaches how this could possibly work (e.g. Deno oak v10.5.1 context.cookies never being set), but have not yet managed to implement it myself in my own…
Limos21
  • 93
  • 5
7
votes
2 answers

How can I return html or json with Deno (oak)?

I've seen: How can I return html or json with deno? but I needed an answer for Oak - Posting below.
funerr
  • 7,212
  • 14
  • 81
  • 129
6
votes
2 answers

Deno - how to implement a 404 page

I have been struggling to implement a 404 page in deno(oak server framework) - if i load any addtress that does not exist, i get just a blank page.. tried: (page404MiddleWare.ts): import {Context, exists, send} from "./deps.ts"; export const…
Daniel
  • 93
  • 7
5
votes
5 answers

How Can I Serve Static Content Alongside Dynamic Routes in A Deno Oak Server

I am used to working with NodeJS and Koa. I've been playing with Deno and have run the example of a static fileserver: /* static_server.js */ import { Application } from 'https://deno.land/x/oak/mod.ts' const port = 8080 const app = new…
Mark Tyers
  • 2,961
  • 4
  • 29
  • 52
5
votes
1 answer

Deno: Access query params in controller

I wrote a couple of apis for a Deno POC. This is the route code: const router = new Router() router.get('/posts', getPosts) .get('/posts/:id', getPostsById) For the second route, I am able to get path param in controller: getPostsById using…
atish
  • 495
  • 5
  • 18
4
votes
1 answer

call multiple middleware / arguments in one variable - deno oak framework

I have this code const keren = async (ctx: Context, next: any) => { console.log('keren'); await next(); } const mantap = async (ctx: Context, next: any) => { console.log('mantap'); await…
user13575712
3
votes
1 answer

Deno.stat is not a function error when using deno deploy

I am having a problem deploying my deno code using deno deploy. The code works perfectly locally using deployctl but fails when deployed. import { Application } from "./deps.ts"; const app = new Application(); // Send static content app.use(async…
3
votes
1 answer

Using oak, serving HTML without extension? (Deno)

Using Oak, how can I serve HTML without the extension? e.g. host:port/home.html -> host:port/home Here's my current code to render my public/views folder: router.get('/:page', async (ctx: Context, next: () => Promise) => { await…
Onyxzen
  • 41
  • 3
3
votes
2 answers

Deno and Docker how to listen for the SIGTERM signal and close the server

I'm trying to find a way to listen in Deno for the Docker SIGTERM signal to close my Oak server. I got this code from Oak website and it works fine when I call the controller.abort() function, using setTimeout or an end-point. However, I want to…
Icaro
  • 14,585
  • 6
  • 60
  • 75
3
votes
2 answers

How to access form body in oak/deno

I'm using oak/deno. I have a form that is submitted from an ejs file served up. How do I access the form body? When I log it to the console, it prints: {type: "form", value: URLSearchParamsImpl {} } The post handler is shown…
ishaangupte
  • 248
  • 2
  • 11
2
votes
0 answers

How do I catch an error from the "listen" method with Oak?

I am trying to catch an error in Oak for the purpose of logging. How do I catch an error with the "app.listen" method? I attempted to use try/catch but it seems like Deno catches the error before I can. try{ app.listen({port: 3000}); …
Hayden
  • 779
  • 10
  • 18
2
votes
1 answer

Http - error writing a body to connection: handshake not complete

i get a 400 bad request error "Your browser sent an invalid request." when i want to reach my website. Here is the error i get in the console : enter image description here My server code : import { Application} from…
Kogami997
  • 33
  • 5
2
votes
2 answers

Generic type RouterContext requires 3 parameters - problem

I'm trying to update the version of the modules in my deno project but after updating them I get the following errors and I don't understand why it happens. has anyone encountered this problem? error: * [ERROR]: Generic type 'RouterContext'…
Boris
  • 69
  • 1
  • 7
2
votes
0 answers

How do I render a native web component with Deno?

I have a native web component (no, not react component)...that I would like to render server side (ssr) in Deno. Here is the web component: import { api } from '/global.js'; class StatsBar extends HTMLElement { constructor() { super(); …
chovy
  • 72,281
  • 52
  • 227
  • 295
2
votes
1 answer

Deno "NotFound: No such file or directory (os error 2)"

I'm working on a Deno side project that runs a server using Oak. I'm trying to run the server with HTTPS and I'm playing around with WebSockets and some basic authentication. The same code runs fine on a different computer but not on my laptop. I'm…
1
2 3 4 5 6