惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Project Zero
Project Zero
T
The Blog of Author Tim Ferriss
云风的 BLOG
云风的 BLOG
Recent Announcements
Recent Announcements
月光博客
月光博客
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog
The GitHub Blog
The GitHub Blog
Last Week in AI
Last Week in AI
罗磊的独立博客
NISL@THU
NISL@THU
酷 壳 – CoolShell
酷 壳 – CoolShell
P
Proofpoint News Feed
H
Help Net Security
L
LINUX DO - 最新话题
MongoDB | Blog
MongoDB | Blog
雷峰网
雷峰网
The Hacker News
The Hacker News
Apple Machine Learning Research
Apple Machine Learning Research
I
Intezer
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Know Your Adversary
Know Your Adversary
Recent Commits to openclaw:main
Recent Commits to openclaw:main
S
Secure Thoughts
爱范儿
爱范儿
aimingoo的专栏
aimingoo的专栏
C
CERT Recently Published Vulnerability Notes
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
N
News and Events Feed by Topic
F
Full Disclosure
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
Recorded Future
Recorded Future
T
Threat Research - Cisco Blogs
博客园 - 三生石上(FineUI控件)
S
Securelist
T
The Exploit Database - CXSecurity.com
Forbes - Security
Forbes - Security
H
Hacker News: Front Page
Security Archives - TechRepublic
Security Archives - TechRepublic
C
Check Point Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
V
Visual Studio Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Tor Project blog
博客园 - 司徒正美
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org

Deno

Deno 2.8 | Deno Claw Patrol: an open-source security firewall for agents | Deno Fresh 2.3: Zero JS by default, View Transitions, and Temporal support | Deno Deno 2.7: Temporal API, Windows ARM, and npm overrides | Deno Build a dinosaur runner game with Deno, pt. 6 | Deno Build a dinosaur runner game with Deno, pt. 5 | Deno Deno Deploy is Generally Available | Deno Introducing Deno Sandbox | Deno Build a dinosaur runner game with Deno, pt. 4 | Deno Build a dinosaur runner game with Deno, pt. 3 | Deno Build a dinosaur runner game with Deno, pt. 2 | Deno React / Next.js Denial-of-Service Vulnerability: Deno Deploy users protected | Deno Deno 2.6: dx is the new npx | Deno Build a dinosaur runner game with Deno, pt. 1 | Deno React Server Functions / Next.js Vulnerability: Deno Deploy users protected | Deno My highlights from the new Deno Deploy | Deno Deno's Other Open Source Projects | Deno How Deno protects against npm exploits | Deno Help Us Raise $200k to Free JavaScript from Oracle | Deno Deno 2.5: Permissions in the config file | Deno Fresh 2.0 Graduates to Beta, Adds Vite Support | Deno Deno 2.4: deno bundle is back | Deno JavaScript™ Trademark Update | Deno What's coming to JavaScript | Deno A brief history of JavaScript | Deno Reports of Deno's Demise Have Been Greatly Exaggerated | Deno An Update on Fresh | Deno How Plaid migrated 100 services to a new database platform 5x faster with Deno | Deno Deno 2.3: Improved deno compile, local npm packages, and more | Deno Add JSR packages with pnpm and Yarn | Deno Zero-config Debugging with Deno and OpenTelemetry | Deno Exploring Art with TypeScript, Jupyter, Polars, and Observable Plot | Deno Deno v Oracle Update 3: Fighting the JavaScript Trademark | Deno Build a custom RAG AI agent in TypeScript and Jupyter | Deno How to get deep traces in your Node.js backend with OTel and Deno | Deno toranoana.deno #20 登録受付中(2025年3月14日) | Deno Node just added TypeScript support. What does that mean for Deno? | Deno The Dino 🦕, the Llama 🦙, and the Whale 🐋 | Deno Publish a lint rule, get a prize | Deno Deno 2.2: OpenTelemetry, Lint Plugins, node:sqlite | Deno If you're not using npm specifiers, you're doing it wrong | Deno How Deno's documentation is evolving | Deno Oracle justified its JavaScript trademark with Node.js—now it wants that ignored | Deno Introducing the JSR open governance board | Deno Intro to Wasm in Deno | Deno Announcing OpenAI on JSR | Deno Deno in 2024 | Deno Goodbye WinterCG, welcome WinterTC | Deno Build a SolidJS app with Deno | Deno Run your Next.js SSR app on Deno Deploy | Deno Solve Advent of Code 2024 with Deno and Win Prizes! | Deno Deno v. Oracle: Canceling the JavaScript Trademark | Deno Deno 2.1: Wasm Imports and other enhancements | Deno Build a Typesafe API with tRPC and Deno | Deno Self-contained Executable Programs with Deno Compile | Deno Build a Database App with Drizzle ORM and Deno | Deno Introducing your new JavaScript package manager: Deno | Deno Announcing Growthbook on JSR | Deno Build an Astro site with Deno | Deno How to convert CommonJS to ESM | Deno Announcing Deno 2 | Deno The Final Touches: What’s New In v2.0.0-rc.10 | Deno Announcing Stable V8 Bindings for Rust | Deno Deno 2.0 Release Candidate | Deno Secure, efficient private npm registries with Cloudsmith and Deno | Deno Painting the Plane as We Fly It: Designing JSR | Deno Introducing Web Cache API support on Deno Deploy | Deno Deno 1.46: The Last 1.x Release | Deno Protect your cloud spend with new Deno Deploy spend limits | Deno What we got wrong about HTTP imports | Deno Benchmarking AWS Lambda Cold Starts Across JavaScript Runtimes | Deno Announcing Supabase on JSR | Deno Deno 1.45: Workspace and Monorepo Support | Deno Introducing KV Backup for Deno Subhosting | Deno A Gentle Intro to TypeScript | Deno Announcing Hono on JSR | Deno How We Made the Deno Language Server Ten Times Faster | Deno How the Guardian uses Deno to audit accessibility and performance across their 2.7 million articles | Deno Introducing More Flexible Domain Association for Deno Subhosting | Deno The stabilization process of the Standard Library has begun | Deno Deno 1.44: Private npm registries, improved Node.js compat, and performance boosts | Deno How we built a secure, performant, multi-tenant cloud platform to run untrusted code | Deno The Deno Standard Library is now available on JSR | Deno How to document your JavaScript package | Deno Your Low Code Solution Needs an Escape Hatch | Deno Deno 1.43: Improved Language Server performance | Deno How Slack used Deno to save months of engineering effort in launching their new platform | Deno JSR Is Not Another Package Manager | Deno Announcing the Hookdeck SDK on JSR | Deno Announcing the Neon Serverless Driver on JSR | Deno An intro to TSConfig for JavaScript Developers | Deno How we built JSR | Deno How Netlify used Deno Subhosting to build a successful edge functions product | Deno Introducing Simpler Project Creation in Deno Deploy | Deno Deno 1.42: Better dependency management with JSR | Deno Introducing deployctl, the command line interface for Deno Deploy | Deno Introducing JSR - the JavaScript Registry | Deno How to add Monaco to a Next.js app and securely run untrusted user code | Deno Survey Results and Roadmap | Deno Deno 1.41: smaller deno compile binaries | Deno
Static Files on Deno Deploy | Deno
2022-02-10 · via Deno

Deno Deploy has always been great at dynamically generating content at the edge. We can run JavaScript code close to users, which can significantly reduce the response time latency. Many applications are not completely dynamic though: they have static assets like CSS files, client side JS, and images.

Until now Deno Deploy has not had a great way to deal with static assets. You had the choice of encoding them into the JavaScript code, hand rolling a CDN, or pulling the files from your GitHub repository. None of these options are ideal.

A new primitive

Deno Deploy now has first class support for static files. Your static files are stored on our network when you deploy your code, and are then distributed around the world close to where your users are. You can use the Deno file system APIs, and fetch to access these files from your JavaScript code running at the edge.

Because the actual serving of the files is still controlled by your code running at the edge, you have full control over all responses, even those to static files. For example, this can be used to:

  • serve files to only to signed-in users
  • add CORS headers to your files
  • modify files with some dynamic content at the edge before they are served
  • serve different files depending on the user’s browser

In Deno Deploy static files are not a completely separate system.

The most basic thing you can do, is read the entire file into memory and serve it to the user:

import { serve } from "https://deno.land/std@0.140.0/http/server.ts";

const HTML = await Deno.readFile("./index.html");

serve(async () => {
  return new Response(HTML, {
    headers: {
      "content-type": "text/html",
    },
  });
});

This works great for small files. For larger files, you can stream the file directly to the user instead of buffering it in memory:

import { serve } from "https://deno.land/std@0.140.0/http/server.ts";

const FILE_URL = new URL("/movie.webm", import.meta.url).href;

serve(async () => {
  const resp = await fetch(FILE_URL);
  return new Response(resp.body, {
    headers: {
      "content-type": "video/webm",
    },
  });
});

Want a directory listing of all the available files? Easy enough with Deno.readDir:

import { serve } from "https://deno.land/std@0.140.0/http/server.ts";

serve(async () => {
  const entries = [];
  for await (const entry of Deno.readDir(".")) {
    entries.push(entry);
  }

  const list = entries.map((entry) => {
    return `<li>${entry.name}</li>`;
  }).join("");

  return new Response(`<ul>${list}</ul>`, {
    headers: {
      "content-type": "text/html",
    },
  });
});

The standard library’s file serving utilities can be utilized to serve static files. These will set appropriate Content-Type headers and support more complex features like Range requests out of the box:

import { serve } from "https://deno.land/std@0.140.0/http/server.ts";
import { serveFile } from "https://deno.land/std@0.140.0/http/file_server.ts";

serve(async (req) => {
  return await serveFile(req, `${Deno.cwd()}/static/index.html`);
});

You can also use Deno Deploy if you’re using a full-fledged HTTP framework like oak to serve your static content:

import { Application } from "https://deno.land/x/oak/mod.ts";

const app = new Application();
app.use(async (ctx) => {
  try {
    await ctx.send({
      root: `${Deno.cwd()}/static`,
      index: "index.html",
    });
  } catch {
    ctx.response.status = 404;
    ctx.response.body = "404 File not found";
  }
});

await app.listen({ port: 8000 });

A full list of the file system APIs Deno Deploy currently supports:

  • Deno.readFile to read a file into memory
  • Deno.readTextFile to read a file into memory as a UTF-8 string
  • Deno.readDir to get a list of files and folders in a folder
  • Deno.open to open a file for reading in chunks (for streaming)
  • Deno.stat to get information about a file or folder (get size or type)
  • Deno.lstat same as above, but doesn’t follow symlinks
  • Deno.realPath to get the path of a file or folder, after resolving symlinks
  • Deno.readLink to get the target for a symlink

Github Integration

Now you may ask yourself: how do I add these newfangled static files to my deployments?

By default, if you’ve linked a GitHub repository to Deploy, all of the files in your repository will available as static files. No changes needed. This is great if you use static files for a few assets stored in your repository, like images or the markdown files for your blog.

However, sometimes you want to generate static files at deploy time. For example when using a framework like Remix.run, or when you use a static site generator. For this scenario we now let you deploy your code and static assets with the deployctl tool. Serving your current working directory at the edge is as simple as:

deployctl deploy --project my-project --prod https://deno.land/std@0.140.0/http/file_server.ts

This works great when you just want to deploy once or if you don’t have your code in version control and always deploy from your local machine, but that isn’t the case for most projects.

Projects hosted on Github will want to use Github Actions to run a build step to generate HTML, or other static content, and then upload to Deno Deploy. We’ve provided a special Github Action step for exactly this purpose:

- name: Upload to Deno Deploy
  uses: denoland/deployctl@v1
  with:
    project: my-project
    entrypoint: main.js
    root: dist

One doesn’t even need to configure any access tokens or secrets for this to work. Just link your GitHub repository in the Deno Deploy dashboard and set the project to “GitHub Actions” deployment mode. Authentication is handled transparently by GitHub Actions.

Why GitHub Actions instead of a custom CI system? GitHub Actions is the de-facto standard for continuous integration now, and many many developers are already familiar with it. Why re-invent something that is already awesome?

Example: A statically generated site

To close out the blog post, here is a real example of a server running on deploy that serves a static site that is built in GitHub Actions. The site is built by a static site generator (in this case the awesome https://lumeland.github.io). Next to the static files, the site also includes a /api/time endpoint that dynamically returns the current time.

Try out the example at https://lume-example.deno.dev/.

Here is the GitHub Actions workflow file the project uses:

name: ci
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  deploy:
    name: deploy
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: read
    steps:
      - name: Clone repository
        uses: actions/checkout@v2

      - name: Install Deno
        uses: denoland/setup-deno@main
        with:
          deno-version: 1.18.2

      - name: Build site
        run: deno run -A https://deno.land/x/lume/ci.ts

      - name: Upload to Deno Deploy
        uses: denoland/deployctl@v1
        with:
          project: lume-example
          entrypoint: server/main.ts

And the actual code that serves the site and the API endpoint:

import { Application, Router } from "https://deno.land/x/oak@v10.2.0/mod.ts";

const app = new Application();



app.use(async (ctx, next) => {
  try {
    await ctx.send({
      root: `${Deno.cwd()}/_site`,
      index: "index.html",
    });
  } catch {
    next();
  }
});

const router = new Router();


router.get("/api/time", (ctx) => {
  ctx.response.body = { time: new Date().toISOString() };
});


app.use(router.routes());
app.use(router.allowedMethods());

await app.listen({ port: 8000 });

How fast are deployments? The time from git push to changes being live around the globe is around 25 seconds on this repo. 15 of those seconds is waiting for the GitHub Actions runner to get ready. For “automatic” mode deployments that don’t involve GitHub Actions, we average between 1-10s deploy times.

If you have any questions, comments, or suggestions, please let us know by opening an issue on feedback repository, or by sending us an email. Happy Denoing!


You can read more about the file system APIs in our docs: https://deno.com/deploy/docs/runtime-fs. More info about the GitHub integration can be found here: https://deno.com/deploy/docs/projects#git-integration.