Git Product home page Git Product logo

oak_deploy's Introduction

oak on Deploy Example

This is just a basic example of oak running on Deno Deploy. It simply echos back the body it was sent in the response to the client. The app is deployed on (oak-deploy-example.deno.dev)[https://oak-deploy-example.deno.dev].

The URL https://github.com/kitsonk/echoServer.ts is what gets deployed, and that is it, and every time I push to the GitHub repo, Deno Deploy will redeploy my application. ๐Ÿช„

I added these 3 lines to the top so that when I was editing the main module, I was getting the proper intellisense with the Deno Language Server in my IDE:

/// <reference path="https://raw.githubusercontent.com/denoland/deployctl/main/types/deploy.fetchevent.d.ts" />
/// <reference path="https://raw.githubusercontent.com/denoland/deployctl/main/types/deploy.ns.d.ts" />
/// <reference path="https://raw.githubusercontent.com/denoland/deployctl/main/types/deploy.window.d.ts" />

Importing oak, just like in the Deno CLI, is super straight forward:

import { Application } from "https://deno.land/x/[email protected]/mod.ts";

Yup, it is that simple!

If you are familiar with oak (or Express or Koa), you would normally expect an app.listen(), but Deno Deploy deals with all the listening for you, so the app only needs to handle the FetchEvents, so what we do is:

addEventListener("fetch", app.fetchEventHandler());

This will have Deno Deploy send FetchEvents into our handler, and for each event, the middleware will be invoked and the response sent to the client.

oak_deploy's People

Contributors

kitsonk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

oak_deploy's Issues

Errors when running locally

Thanks for the demo project! I was trying it out and wanted to run it locally but am running into errors.

Versions

deno --version
deno 1.9.0 (release, x86_64-apple-darwin)
v8 9.1.269.5
typescript 4.2.2

deployctl --versions                 
deployctl 0.2.0

When I run deployctl run --watch ./echoServer.ts

oak_deploy git:(main) โœ— deployctl run --watch ./echoServer.ts
Check file:///Users/jrai/git/oak_deploy/$deno$eval.ts
error: TS2339 [ERROR]: Property 'cwd' does not exist on type 'typeof Deno'.
      path = Deno.cwd();
                  ~~~
    at https://deno.land/[email protected]/path/win32.ts:43:19

TS2339 [ERROR]: Property 'cwd' does not exist on type 'typeof Deno'.
      path = Deno.env.get(`=${resolvedDevice}`) || Deno.cwd();
                                                        ~~~
    at https://deno.land/[email protected]/path/win32.ts:53:57

TS2339 [ERROR]: Property 'cwd' does not exist on type 'typeof Deno'.
      path = Deno.cwd();
                  ~~~
    at https://deno.land/[email protected]/path/posix.ts:36:19

TS2694 [ERROR]: Namespace 'Deno' has no exported member 'Reader'.
  async readFrom(r: Deno.Reader): Promise<number> {
                         ~~~~~~
    at https://deno.land/[email protected]/io/buffer.ts:207:26

TS2694 [ERROR]: Namespace 'Deno' has no exported member 'ReaderSync'.
  readFromSync(r: Deno.ReaderSync): number {
                       ~~~~~~~~~~
    at https://deno.land/[email protected]/io/buffer.ts:237:24

TS2694 [ERROR]: Namespace 'Deno' has no exported member 'Reader'.
export async function readAll(r: Deno.Reader): Promise<Uint8Array> {
                                      ~~~~~~
    at https://deno.land/[email protected]/io/util.ts:25:39

TS2694 [ERROR]: Namespace 'Deno' has no exported member 'ReaderSync'.
export function readAllSync(r: Deno.ReaderSync): Uint8Array {
                                    ~~~~~~~~~~
    at https://deno.land/[email protected]/io/util.ts:50:37

TS2694 [ERROR]: Namespace 'Deno' has no exported member 'Writer'.
export async function writeAll(w: Deno.Writer, arr: Uint8Array) {
                                       ~~~~~~
    at https://deno.land/[email protected]/io/util.ts:76:40

TS2694 [ERROR]: Namespace 'Deno' has no exported member 'WriterSync'.
export function writeAllSync(w: Deno.WriterSync, arr: Uint8Array): void {
                                     ~~~~~~~~~~
    at https://deno.land/[email protected]/io/util.ts:104:38

TS2694 [ERROR]: Namespace 'Deno' has no exported member 'Reader'.
  r: Deno.Reader,
          ~~~~~~
    at https://deno.land/[email protected]/io/util.ts:141:11

TS2694 [ERROR]: Namespace 'Deno' has no exported member 'ReaderSync'.
  r: Deno.ReaderSync,
          ~~~~~~~~~~
    at https://deno.land/[email protected]/io/util.ts:188:11

TS2694 [ERROR]: Namespace 'Deno' has no exported member 'Reader'.
type Reader = Deno.Reader;
                   ~~~~~~
    at https://deno.land/[email protected]/io/bufio.ts:7:20

TS2694 [ERROR]: Namespace 'Deno' has no exported member 'Writer'.
type Writer = Deno.Writer;
                   ~~~~~~
    at https://deno.land/[email protected]/io/bufio.ts:8:20

TS2694 [ERROR]: Namespace 'Deno' has no exported member 'WriterSync'.
type WriterSync = Deno.WriterSync;
                       ~~~~~~~~~~
    at https://deno.land/[email protected]/io/bufio.ts:9:24

TS2304 [ERROR]: Cannot find name 'setTimeout'.
    setTimeout((): void => {
    ~~~~~~~~~~
    at https://deno.land/[email protected]/async/delay.ts:5:5

TS2339 [ERROR]: Property 'errors' does not exist on type 'typeof Deno'.
      throw new Deno.errors.UnexpectedEof();
                     ~~~~~~
    at https://deno.land/[email protected]/textproto/mod.ts:73:22

TS2339 [ERROR]: Property 'errors' does not exist on type 'typeof Deno'.
      throw new Deno.errors.InvalidData(
                     ~~~~~~
    at https://deno.land/[email protected]/textproto/mod.ts:75:22

TS2339 [ERROR]: Property 'errors' does not exist on type 'typeof Deno'.
      if (kv === null) throw new Deno.errors.UnexpectedEof();
                                      ~~~~~~
    at https://deno.land/[email protected]/textproto/mod.ts:82:39

TS2339 [ERROR]: Property 'errors' does not exist on type 'typeof Deno'.
        throw new Deno.errors.InvalidData(
                       ~~~~~~
    at https://deno.land/[email protected]/textproto/mod.ts:88:24

TS2694 [ERROR]: Namespace 'Deno' has no exported member 'Reader'.
export function emptyReader(): Deno.Reader {
                                    ~~~~~~
    at https://deno.land/[email protected]/http/_io.ts:11:37

TS2694 [ERROR]: Namespace 'Deno' has no exported member 'Reader'.
export function bodyReader(contentLength: number, r: BufReader): Deno.Reader {
                                                                      ~~~~~~
    at https://deno.land/[email protected]/http/_io.ts:19:71

TS2694 [ERROR]: Namespace 'Deno' has no exported member 'Reader'.
export function chunkedBodyReader(h: Headers, r: BufReader): Deno.Reader {
                                                                  ~~~~~~
    at https://deno.land/[email protected]/http/_io.ts:41:67

TS2339 [ERROR]: Property 'errors' does not exist on type 'typeof Deno'.
          throw new Deno.errors.UnexpectedEof();
                         ~~~~~~
    at https://deno.land/[email protected]/http/_io.ts:63:26

TS2339 [ERROR]: Property 'errors' does not exist on type 'typeof Deno'.
    if (line === null) throw new Deno.errors.UnexpectedEof();
                                      ~~~~~~
    at https://deno.land/[email protected]/http/_io.ts:69:39

TS2339 [ERROR]: Property 'errors' does not exist on type 'typeof Deno'.
      throw new Deno.errors.InvalidData("Invalid chunk size");
                     ~~~~~~
    at https://deno.land/[email protected]/http/_io.ts:74:22

TS2339 [ERROR]: Property 'errors' does not exist on type 'typeof Deno'.
          throw new Deno.errors.UnexpectedEof();
                         ~~~~~~
    at https://deno.land/[email protected]/http/_io.ts:80:26

TS2339 [ERROR]: Property 'errors' does not exist on type 'typeof Deno'.
          throw new Deno.errors.UnexpectedEof();
                         ~~~~~~
    at https://deno.land/[email protected]/http/_io.ts:85:26

TS2339 [ERROR]: Property 'errors' does not exist on type 'typeof Deno'.
          throw new Deno.errors.UnexpectedEof();
                         ~~~~~~
    at https://deno.land/[email protected]/http/_io.ts:97:26

TS2339 [ERROR]: Property 'errors' does not exist on type 'typeof Deno'.
          throw new Deno.errors.UnexpectedEof();
                         ~~~~~~
    at https://deno.land/[email protected]/http/_io.ts:101:26

TS2339 [ERROR]: Property 'errors' does not exist on type 'typeof Deno'.
        throw new Deno.errors.UnexpectedEof();
                       ~~~~~~
    at https://deno.land/[email protected]/http/_io.ts:109:24

TS2339 [ERROR]: Property 'errors' does not exist on type 'typeof Deno'.
    throw new Deno.errors.InvalidData("Missing trailer header.");
                   ~~~~~~
...
Found 188 errors.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.