-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
44 lines (39 loc) · 1.19 KB
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import * as msgpack from 'https://esm.sh/@msgpack/msgpack';
import * as yaml from 'https://deno.land/std/yaml/mod.ts';
import { Hono } from 'https://deno.land/x/hono/mod.ts';
import { serve } from 'https://deno.land/std/http/server.ts';
const app = new Hono();
app.get('/:file{.*.mpk}', async (ctx) => {
const file = ctx.req.param('file').replace('.mpk', '.yaml')
const txt = await Deno.readTextFile('yaml/' + file);
const obj = yaml.parse(txt);
const buf = msgpack.encode(obj);
return new Response(buf, {
headers: {
'Content-Type': 'application/x-msgpack',
},
status: 200,
});
})
app.get('/:file{.*.json}', async (ctx) => {
const file = ctx.req.param('file').replace('.json', '.yaml')
const txt = await Deno.readTextFile('yaml/' + file);
const obj = yaml.parse(txt);
return new Response(JSON.stringify(obj), {
headers: {
'Content-Type': 'application/json',
},
status: 200,
});
});
app.get('/:file{.*.yaml}', async (ctx) => {
const file = ctx.req.param('file');
const txt = await Deno.readTextFile('yaml/' + file);
return new Response(txt, {
headers: {
'Content-Type': 'application/x-yaml',
},
status: 200,
});
});
serve(app.fetch);