New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ecklf-tmp-runtime-test

Package Overview
Dependencies
Maintainers
1
Versions
144
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ecklf-tmp-runtime-test

First, you'll need a `vercel.json` file in your project:

  • 1.0.102
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
19
increased by90%
Maintainers
1
Weekly downloads
 
Created
Source

Usage

First, you'll need a vercel.json file in your project:

{
  "functions": {
    "api/**/*.rs": {
      "runtime": "vercel-rust@3.1.2"
    }
  }
}

A Vercel Function will be created for every file that matches api/**/*.rs.

api/handler.rs:

use serde_json::json;
use vercel_runtime::{
    lambda_http::{http::StatusCode, Error as LambdaError, Response},
    run, IntoResponse, ProxyError, ProxyRequest,
};

#[tokio::main]
async fn main() -> Result<(), LambdaError> {
    run(handler).await?;
    Ok(())
}

pub async fn handler(_req: ProxyRequest) -> Result<impl IntoResponse, ProxyError> {
    let response = Response::builder()
        .status(StatusCode::OK)
        .header("Content-Type", "application/json")
        .body(
            json!({
              "message": "你好,世界"
            })
            .to_string(),
        )?;

    Ok(response)
}

Finally we need a Cargo.toml file at the root of your repository.

# You can specify a library for shared logic here (optional)
# [lib]
# path = "src-rs/lib.rs"

# Each handler has to be specified as [[bin]]
[[bin]]
name = "handler"
path = "api/handler.rs"

Dependencies

This Builder supports installing dependencies defined in the Cargo.toml file.

Furthermore, more system dependencies can be installed at build time with the presence of a shell build.sh file in the same directory as the entrypoint file.

Local Development

With vercel dev and vercel-rust, you can develop your Rust-based lambdas on your own machine.

During local development with vercel dev, ensure rust and cargo are already installed and available in your PATH, since they will not be installed automatically. The recommended way to install is with rustup.

Contributing

Since this project contains both Rust and Node.js code, you need to install the relevant dependencies. If you're only working on the JavaScript side, you only need to install those dependencies (and vice-versa).

# install node dependencies
npm install

# install cargo dependencies
cargo fetch

Runtime Invocation Flowchart

graph TD
    A["Lambda Invocation"] --> |"process_request(event: LambdaEvent&lt;VercelEvent&gt;) → ProxyRequest"| B[ProxyRequest]
    B --> |"handler_fn(req: ProxyRequest) → Future&lt;Output = Result&lt;impl IntoResponse, ProxyError&gt;&gt;"| C["Runtime calls handler_fn"]
    C --> |"Ok(r) => process_response(r)"| D["ProxyResponse"]
    C --> |"Err(e) => process_error(e)"| E["ProxyError"]

Upon a request a LambdaEvent containing a VercelEvent is mapped to a ProxyRequest which can be consumed in the handler function. The Result of the handler function will be mapped into a ProxyResponse or ProxyError.

FAQ

  • The Root Cargo.toml is setting up the workspaces for the endpoints.
  • The Endpoints (api/**/handler.rs) export a function with the signature: pub async fn handler(_req: ProxyRequest) -> Result<impl IntoResponse, ProxyError>.
 .
├──  api
│  ├──  endpoint_1
│  │  ├──  Cargo.toml
│  │  └──  src
│  │     └──  main.rs
│  └──  endpoint_2
│     ├──  Cargo.toml
│     └──  src
│        └──  main.rs
├──  Cargo.lock
└──  Cargo.toml

What should be in the documentation

# Show `debug` statements in logs
VERCEL_BUILDER_DEBUG=true

Merging Endpoints?

Builder

  • Installs the Rust toolchain
  • Injects a pre-defined entry package in the workspace that imports all endpoint handler fn (proc macro) with runtime initialization and routing logic.

Event

[https://github.com/awslabs/aws-lambda-rust-runtime/releases/tag/v0.3.0](Base Lambda Runtime Release Notes)

files: {
  "files": {
    "api/Cargo.lock": {
      "type": "FileFsRef",
      "mode": 33188,
      "fsPath": "/vercel/path0/api/Cargo.lock"
    },
    "api/Cargo.toml": {
      "type": "FileFsRef",
      "mode": 33188,
      "fsPath": "/vercel/path0/api/Cargo.toml"
    },
    "api/user.rs": {
      "type": "FileFsRef",
      "mode": 33188,
      "fsPath": "/vercel/path0/api/user.rs"
    },
    ".vercelignore": {
      "type": "FileFsRef",
      "mode": 33188,
      "fsPath": "/vercel/path0/.vercelignore"
    },
    "package.json": {
      "type": "FileFsRef",
      "mode": 33188,
      "fsPath": "/vercel/path0/package.json"
    },
    "pnpm-lock.yaml": {
      "type": "FileFsRef",
      "mode": 33188,
      "fsPath": "/vercel/path0/pnpm-lock.yaml"
    },
    "vercel.json": {
      "type": "FileFsRef",
      "mode": 33188,
      "fsPath": "/vercel/path0/vercel.json"
    }
  },
  "entrypoint": "api/user.rs",
  "workPath": "/vercel/path0",
  "repoRootPath": "/vercel/path0",
  "config": {
    "zeroConfig": true,
    "functions": {
      "api/**/*.rs": {
        "runtime": "ecklf-tmp-runtime-test@1.0.4"
      }
    },
    "projectSettings": {
      "createdAt": 1674047862614,
      "installCommand": null,
      "buildCommand": null,
      "devCommand": null,
      "outputDirectory": null,
      "rootDirectory": null,
      "framework": null,
      "nodeVersion": "18.x"
    },
    "framework": null,
    "nodeVersion": "18.x"
  },
  "meta": {
    "skipDownload": true,
    "cliVersion": "28.12.7"
  }
}

FAQs

Package last updated on 08 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc