Skip to content

Instantly share code, notes, and snippets.

import { serve } from "https://deno.land/std/http/server.ts";
const s = serve({ port: 3000 });
for await (const req of s) {
req.respond({ body: JSON.stringify({body: "Hello World" })});
}
import { Application } from "https://deno.land/x/oak/mod.ts";
const app = new Application();
app.use(ctx => {
ctx.response.body = { body: "Hello World" };
});
await app.listen({port: 3000});
import { serveTLS } from "https://deno.land/std/http/server.ts";
const certFile: string= Deno.env.toObject()["CERT_FILE"];
const keyFile: string= Deno.env.toObject()["KEY_FILE"];
const options = {
hostname: "localhost",
port: 3000,
certFile,
keyFile
};
import { serve } from "https://deno.land/std/http/server.ts";
import { v1 } from "https://deno.land/std/uuid/mod.ts";
const s = serve({ port: 3000 });
const decoder = new TextDecoder();
for await (const req of s) {
const body=JSON.parse(decoder.decode(await Deno.readAll(req.body)));
const uuids=[];
for(let i=0; i<body.requiredUuids; i++)
import { serve } from "https://deno.land/std/http/server.ts";
const text = await Deno.readTextFile("/var/tmp/sample.json");
const json = JSON.parse(text);
const s = serve({ port: 3000 });
for await (const req of s) {
req.respond({ status: 200,
body: JSON.stringify(json) });
}
import { Application } from "https://deno.land/x/oak/mod.ts";
const text = await Deno.readTextFile("/var/tmp/sample.json");
const json = JSON.parse(text);
const app = new Application();
app.use((ctx) => {
ctx.response.body = json;
});
[
{
"_id": "604179e4d130a49496cc49d0",
"index": 0,
"guid": "9216f643-8103-4916-8a61-c1c98cc4f2e7",
"isActive": false,
"balance": "$2,336.88",
"picture": "http://placehold.it/32x32",
"age": 36,
"eyeColor": "green",
import { serve } from "https://deno.land/std/http/server.ts";
const get1 = JSON.parse(await Deno.readTextFile("./getData.json"));
const get2 = JSON.parse(await Deno.readTextFile("./getData2.json"));
const post1 = JSON.parse(await Deno.readTextFile("./postData.json"));
const s = serve({ port: 3000 });
for await (const req of s) {
console.log(req.url);
switch(req.method) {
@mayankchoubey
mayankchoubey / deno_universal_body_parser_example.ts
Last active April 3, 2021 06:38
An example for universal body parser
import { parse } from "https://raw.githubusercontent.com/mayankchoubey/deno-body-parser/main/mod.ts";
import { serve } from "https://deno.land/std/http/server.ts";
const dataStorePath='/private/var/tmp/uploads';
const encoder=new TextEncoder();
const server = serve({ hostname: "0.0.0.0", port: 8080 });
for await (const request of server) {
switch(request.url) {
case '/uploads': {
const body=await parse(request, {saveBodyToFile: true, saveFilePath: dataStorePath});
@mayankchoubey
mayankchoubey / server.ts
Created June 17, 2021 06:03
Ephemeral file server - main
import {PORT, DISK_FILE_PATH} from "./constants.ts";
import {handleRequest} from "./router.ts";
import {getStatus} from "./utils.ts";
if(!await checkSandbox(DISK_FILE_PATH)) {
console.error('Required read/write/net access is denied, exiting');
Deno.exit(1);
}
const listener = Deno.listen({ port: PORT });