-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmod.ts
98 lines (84 loc) · 2.73 KB
/
mod.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { Application, Router } from "https://deno.land/x/oak/mod.ts";
import * as utils from "./src/utils.ts"
import * as controllers from "./src/controllers.ts"
import * as cow from "https://deno.land/x/cowsay/mod.ts"
import {_layout_template} from "./src/views/_shared/_layout.ts"
import { css } from "./src/views/_shared/_layout.css.ts"
import { parse } from "https://deno.land/std/flags/mod.ts";
import * as ink from "https://deno.land/x/ink/mod.ts"
import { renderAsync } from "./src/engine.ts"
const router = new Router();
router
// @ts-ignore
.get("/", context => {
context.response.headers.set("Content-Type", "text/html")
const body = _layout_template.replace("/*@@CSS@@*/", css)
context.response.body = body
})
// @ts-ignore
.get("/render/:com", async (context) => {
// @ts-ignore
const model = controllers.getModel(context.params.com)
// @ts-ignore
const result = await renderAsync(context.params.com, model);
context.response.headers.set("Content-Type", "application/json")
context.response.body = result
})
// @ts-ignore
.get("/api/deletefolder/:folder", async (context) => {
// @ts-ignore
const result = await utils.deleteFolder(context.params.folder)
context.response.headers.set("Content-Type", "application/json")
context.response.body = result
})
// @ts-ignore
.get("/api/run/:command", async (context) => {
// @ts-ignore
const result = await utils.runDeno(context.params.command)
context.response.headers.set("Content-Type", "application/json")
context.response.body = result
})
// @ts-ignore
.get("/api/folders/:folder", async (context) => {
const folder = context.params.folder
context.response.headers.set("Content-Type", "application/json")
if (folder === "_root_") {
context.response.body = utils.getCacheTree()
} else {
// @ts-ignore
context.response.body = utils.getFiles(folder)
}
})
// @ts-ignore
.get("/api/stop", async (context) => {
context.response.headers.set("Content-Type", "application/json")
Deno.exit(0)
})
// @ts-ignore
.get("/api/denolatest/", async (context) => {
const version = await utils.fetchDenoVersion()
context.response.headers.set("Content-Type", "application/json")
context.response.body = version
})
const app = new Application();
app.use(router.routes());
app.use(router.allowedMethods());
const opts = {
default: {
port: 8080
},
alias: {
port: "p"
}
}
const argsv = parse(Deno.args, opts)
const urlText = ink.colorize(`<b>Open: <red>http://localhost:${argsv.port}</red></b>`)
const text = cow.say({
text: urlText,
cow: "kitten"
})
export async function run() {
console.log(text)
await app.listen(`localhost:${argsv.port}`)
}
await run();