Code Monkey home page Code Monkey logo

now-deno's Introduction

now-deno

Deno builder for Vercel - run Deno on vercel. 🦕 + λ = ❤️

This builder allows you to run Deno as a lambda on vercel.

Usage

If you're unfamiliar with vercel runtimes, please read the runtime docs first. This runtime can be used like any other Community Runtime.

// vercel.json
{
  "functions": {
    "api/**/*.{j,t}s": {
      "runtime": "[email protected]"
    }
  }
}

Note: You need vercel v17.x or above to use the above configuration.

// api/hello.ts
import {
  APIGatewayProxyEvent,
  APIGatewayProxyResult,
  Context,
} from 'https://deno.land/x/lambda/mod.ts';

export async function handler(
  event: APIGatewayProxyEvent,
  context: Context
): Promise<APIGatewayProxyResult> {
  return {
    statusCode: 200,
    body: `Welcome to deno ${Deno.version.deno} 🦕`,
    headers: {
      'content-type': 'text/html; charset=utf-8',
    },
  };
}

That's the simplest way to use this runtime!

Advanced usage

Specific Deno version

To use a specific version of Deno you can specify a environment variable in your vercel.json:

// vercel.json
{
  "functions": {
    ...
  },
  "env": {
    "DENO_VERSION": "0.42.0"
  }
}

Unstable mode

To use Deno's unstable mode you can specify the environment variable DENO_UNSTABLE in your vercel.json:

// vercel.json
{
  "functions": {
    ...
  },
  "env": {
    "DENO_UNSTABLE": "true"
  }
}

TS Config

To pass a custom config, you can specify the variable DENO_CONFIG in your now.json:

// now.json
{
  "functions": {
    ...
  },
  "env": {
    "DENO_CONFIG": "tsconfig.json"
  }
}

Custom pre-package script

You can place a build.sh function in the root of your deploy directory. This will be executed before the function is packaged up.

vercel dev

vercel dev is currently only supported on macOS and Linux. It is not supported on Windows.

If you have have deno installed in your path then you can use vercel dev with this runtime. It should work just like any other runtime.

Credits

This was only possible due to the great work of Andy Hayden who made the first attempts at running deno in a lambda function.

now-deno's People

Contributors

dependabot[bot] avatar hayd avatar khrome83 avatar kt3k avatar lucacasonato avatar wesleycoder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

now-deno's Issues

Doesn't work with deno-postgres

I'm trying to use deno-postgres with now-deno as this example. But this doesn't deploy to now with the following build time error.

...
2020-02-13T16:22:18.209Z  Download https://deno.land/x/[email protected]/md5.ts
2020-02-13T16:22:18.209Z  Download https://deno.land/x/postgres/encode.ts
2020-02-13T16:22:18.209Z  Download https://deno.land/x/postgres/decode.ts
2020-02-13T16:22:18.209Z  Download https://deno.land/x/postgres/oid.ts
2020-02-13T16:22:18.209Z  Download https://deno.land/x/postgres/deferred.ts
2020-02-13T16:22:18.209Z  
2020-02-13T16:22:18.209Z  error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'esnext' or 'system'.
2020-02-13T16:22:18.210Z  
2020-02-13T16:22:18.210Z  ► https://deno.land/[email protected]/testing/runner.ts:294:5
2020-02-13T16:22:18.210Z  
2020-02-13T16:22:18.210Z  294 if (import.meta.main) {
2020-02-13T16:22:18.210Z          ~~~~~~~~~~~
2020-02-13T16:22:18.210Z  
2020-02-13T16:22:18.210Z  
2020-02-13T16:22:18.210Z      at buildDenoLambda (/zeit/82db6065a0e33879/.build-utils/.builder/node_modules/now-deno/dist/index.js:63:15)
2020-02-13T16:22:18.210Z      at runMicrotasks (<anonymous>)
2020-02-13T16:22:18.210Z      at processTicksAndRejections (internal/process/task_queues.js:93:5)
2020-02-13T16:22:18.270Z  worker exited with code 20 and signal null
2020-02-13T16:22:20.560Z  Done with "api/read.ts"

Change tags of repo

Because of the change of name from Zeit to Vercel (blog post here), it would be relevant to change the repo tags (topics) to reflect that
image of repo topics - zeit-now,deno,lambda,serverless,zeit

Remove 'deno bundle'

Instead of bundling the application using deno bundle before deployment it should just be precompiled with deno fetch and then use .deno_dir for dependencies.

`now dev` failed to find deno exacutable when deno is installed via asdf

If I installed deno via asdf, now dev doesn't seem working with the following error:

$ npx now dev
Now CLI 17.0.3 dev (beta) — https://zeit.co/feedback
> Creating initial build
> Success! Build completed
> Ready! Available at http://localhost:3000
unknown command: deno. Perhaps you have to reshim?
unknown command: deno. Perhaps you have to reshim?
error: bad deno executable
Unexpected bootstrap error when calling AWS_LAMBDA_RUNTIME_API /init/error:
InitException: bad deno executable
    at Lambda.<anonymous> (/Users/kt3k/s/now-deno-example/node_modules/now/dist/index.js:2:3545645)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/kt3k/s/now-deno-example/node_modules/now/dist/index.js:2:3543532)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

If I removed asdf-installed deno and installed it with the official installer script, then it worked. Maybe this isn't a issue of this tool, but do you have any idea about the cause of the above error? @lucacasonato

Specify deno-lambda version

Atm now-deno uses the latest release but I think it would be good for users to (optionally?) pass a version number for the deno-lambda release to use.

(In the future this will match the deno version.)

Add tests

  • Add automatic now deployment tests to check that the now build succeeds

WebSocket on Lambda with Zeit Now

Hi, @lucacasonato!

First of all, thank you for the effort and nice bits of code you put on this project.

I tried to use it on a POC, but I'm getting permission errors on my Serverless function.

I already tried to debug and search for a possible explanation of how it works and how it starts my file on top of Deno, but I couldn't find any solution.

Could you help me with that issue?

I have a open PR ( at uqmessias/web-socket-react-native#1) with the code you can use to debug if you wish.

Unable to add params outside of --unstable

note: Remember to include the --allow-read flag when rendering from files

I noticed this when trying to access a file. Vercel allows includedFiles allowing lambdas to reference files that are compiled as part of it. Technically I don't think it "goes to disk", but I am seeing this permissions issues.

Is this supported today, and not documented? Or is this adding additional ENV variables like DENO_UNSTABLE to support?

Issues Bundling

Is there anything that prevents vercel dev from bundling the contents?

Every time I run a lambda, I have no issues. But when I try to manually bundle it, or run vercel dev I get this.

error: Uncaught AssertionError: Assertion failed.
    at Object.assert ($deno$/util.ts:33:11)
    at compile ($deno$/compiler.ts:1355:5)
    at async tsCompilerOnMessage ($deno$/compiler.ts:1548:22)
    at async workerMessageRecvCallback ($deno$/runtime_worker.ts:74:9)

So now I am not sure of the issue. If I remove mustache, it works. I had issues with multiple things that I am importing. I am not saying the vanilla code is an issue. I am trying to understand why it's so fragile, and what these libraries are using that can be bundled outside of now-deno, but in combination with now-deno just fail.

vercel.dev

{
  "version": 2,
  "functions": {
    "api/**/*.{j,t}s": {
      "runtime": "[email protected]",
      "includeFiles": "**/*.html"
    }
  },
  "env": {
    "DENO_UNSTABLE": "true"
  }
}

api/test/index.ts

import {
  APIGatewayProxyEvent,
  APIGatewayProxyResult,
  Context,
} from "https://deno.land/x/lambda/mod.ts";
import { renderFile } from "https://deno.land/x/mustache/mod.ts";

export async function handler(
  event: APIGatewayProxyEvent,
  context: Context
): Promise<APIGatewayProxyResult> {
  return {
    statusCode: 200,
    body: await renderFile(`template.html`, {
      txt: "HEY",
    }),
    headers: {
      "content-type": "text/html; charset=utf-8",
    },
  };
}

api/test/template.html

<p>Hello {{ txt }}</p>

Add optional '--config' flag

In the upcoming deno 1.0.0 release, clients can bundle a module with their own tsconfig file with --config flag, addressed in the release note in v1.0.0-rc2 here

Looking at the source code, the runtime hasn't implement this option yet.

['bundle', entrypointPath, binPath, ...(unstable ? ['--unstable'] : [])],

In addition, since it needs config file location, maybe creating new environment value tsconfig under env parameter in now.json would be a good idea in this case.

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.