1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Deno DeployでDeno.env.setとDeno.env.deleteを実装する

Last updated at Posted at 2023-02-24

普通に使うとエラーがでるー
image.png

がんばって実装する。

YOUR_PRJECT_NAMEYOUR_ACCESS_TOKENは書き換えてくだあい

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

Deno.env.bulkSet = async obj => fetch(`https://dash.deno.com/_api/projects/YOUR_PRJECT_NAME/env`, {
  method: 'PATCH',
  headers: {
    'Content-Type': 'application/json',
    'cookie': 'token=YOUR_ACCESS_TOKEN'
  },
  body: JSON.stringify(obj)
})
Deno.env.set = async (key, value) => Deno.env.bulkSet({[key]: value})
Deno.env.delete = async key => Deno.env.bulkSet({[key]: null})
Deno.env.bulkDelete = async keys => Deno.env.bulkSet(Object.fromEntries(keys.map(key => [key, null])))

serve(async (req: Request) => {
    await Deno.env.set('SOME_VAR', 'Value')
    await Deno.env.delete('SOME_VAR')
    await Deno.env.bulkSet({ lastName: "John", firstName: "Doe" })
    await Deno.env.bulkDelete(['a', 'b'])
    return new Response("Hello World")
});

YOUR_PRJECT_NAME

image.png

YOUR_ACCESS_TOKEN

image.png
image.png
image.png
image.png
image.png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?