dodanie tempstream
Summary: Ref T2491 Reviewers: #reviewers Subscribers: jenkins-user Maniphest Tasks: T2491 Differential Revision: https://hub.sealcode.org/D1174
This commit is contained in:
parent
1168aa3bd0
commit
9d8ca9e751
13
package-lock.json
generated
13
package-lock.json
generated
@ -14,7 +14,8 @@
|
|||||||
"multiple-scripts-tmux": "^1.0.3",
|
"multiple-scripts-tmux": "^1.0.3",
|
||||||
"nodemon": "^2.0.7",
|
"nodemon": "^2.0.7",
|
||||||
"sealious": "^0.13.38",
|
"sealious": "^0.13.38",
|
||||||
"stimulus": "^2.0.0"
|
"stimulus": "^2.0.0",
|
||||||
|
"tempstream": "^0.0.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sealcode/ansi-html-stream": "^1.0.1",
|
"@sealcode/ansi-html-stream": "^1.0.1",
|
||||||
@ -8662,6 +8663,11 @@
|
|||||||
"node": ">= 6"
|
"node": ">= 6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/tempstream": {
|
||||||
|
"version": "0.0.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/tempstream/-/tempstream-0.0.7.tgz",
|
||||||
|
"integrity": "sha512-Etn/RJSwL+u7QGpk3acTXkxsJ8wgg20glZt1sQ0Zah1pPhoxqqOANjS9WrlILYfcdr8XrAgnhmk1ntN+Y2x0ew=="
|
||||||
|
},
|
||||||
"node_modules/term-size": {
|
"node_modules/term-size": {
|
||||||
"version": "2.2.1",
|
"version": "2.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/term-size/-/term-size-2.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/term-size/-/term-size-2.2.1.tgz",
|
||||||
@ -16608,6 +16614,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"tempstream": {
|
||||||
|
"version": "0.0.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/tempstream/-/tempstream-0.0.7.tgz",
|
||||||
|
"integrity": "sha512-Etn/RJSwL+u7QGpk3acTXkxsJ8wgg20glZt1sQ0Zah1pPhoxqqOANjS9WrlILYfcdr8XrAgnhmk1ntN+Y2x0ew=="
|
||||||
|
},
|
||||||
"term-size": {
|
"term-size": {
|
||||||
"version": "2.2.1",
|
"version": "2.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/term-size/-/term-size-2.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/term-size/-/term-size-2.2.1.tgz",
|
||||||
|
@ -25,7 +25,8 @@
|
|||||||
"multiple-scripts-tmux": "^1.0.3",
|
"multiple-scripts-tmux": "^1.0.3",
|
||||||
"nodemon": "^2.0.7",
|
"nodemon": "^2.0.7",
|
||||||
"sealious": "^0.13.38",
|
"sealious": "^0.13.38",
|
||||||
"stimulus": "^2.0.0"
|
"stimulus": "^2.0.0",
|
||||||
|
"tempstream": "^0.0.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sealcode/ansi-html-stream": "^1.0.1",
|
"@sealcode/ansi-html-stream": "^1.0.1",
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { Context } from "sealious";
|
import { Templatable, tempstream } from "tempstream";
|
||||||
|
import { Readable } from "stream";
|
||||||
|
import { BaseContext } from "koa";
|
||||||
|
|
||||||
export default async function html(
|
export default function html(ctx: BaseContext, body: Templatable): Readable {
|
||||||
_context: Context,
|
ctx.set("content-type", "text/html;charset=utf-8");
|
||||||
body: string
|
return tempstream/* HTML */ ` <!DOCTYPE html>
|
||||||
): Promise<string> {
|
|
||||||
return /* HTML */ `<!DOCTYPE html>
|
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
@ -2,22 +2,24 @@ import Router from "@koa/router";
|
|||||||
import { Context, Middlewares } from "sealious";
|
import { Context, Middlewares } from "sealious";
|
||||||
import html from "../html";
|
import html from "../html";
|
||||||
import { NewTask, TaskList } from "../views/tasks";
|
import { NewTask, TaskList } from "../views/tasks";
|
||||||
|
import { BaseContext } from "koa";
|
||||||
|
import { Readable } from "stream";
|
||||||
|
|
||||||
const router = new Router();
|
const router = new Router();
|
||||||
|
|
||||||
export async function MainView(context: Context): Promise<string> {
|
export async function MainView(ctx: BaseContext): Promise<Readable> {
|
||||||
return await html(
|
return html(
|
||||||
context,
|
ctx,
|
||||||
/* HTML */ `<title>My ToDo App</title>
|
/* HTML */ ` <title>My ToDo App</title>
|
||||||
<body>
|
<body>
|
||||||
<h1>My ToDo App</h1>
|
<h1>My ToDo App</h1>
|
||||||
${await TaskList(context)} ${NewTask()}
|
${await TaskList(ctx.$context)} ${NewTask()}
|
||||||
</body>`
|
</body>`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
router.get("/", Middlewares.extractContext(), async (ctx) => {
|
router.get("/", Middlewares.extractContext(), async (ctx) => {
|
||||||
ctx.body = await MainView(ctx.$context);
|
ctx.body = MainView(ctx);
|
||||||
});
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@ -6,7 +6,7 @@ import html from "../html";
|
|||||||
const router = new Router();
|
const router = new Router();
|
||||||
|
|
||||||
router.get("/", Middlewares.extractContext(), async (ctx) => {
|
router.get("/", Middlewares.extractContext(), async (ctx) => {
|
||||||
ctx.body = await html(ctx.$context, LoginForm());
|
ctx.body = html(ctx, LoginForm());
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
@ -27,8 +27,8 @@ router.post(
|
|||||||
ctx.redirect("/user");
|
ctx.redirect("/user");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
ctx.status = 422;
|
ctx.status = 422;
|
||||||
ctx.body = await html(
|
ctx.body = html(
|
||||||
ctx.$context,
|
ctx,
|
||||||
LoginForm(ctx.$body.username as string, (e as Error).message)
|
LoginForm(ctx.$body.username as string, (e as Error).message)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ router.post(
|
|||||||
done: false,
|
done: false,
|
||||||
})
|
})
|
||||||
.save(ctx.$context);
|
.save(ctx.$context);
|
||||||
ctx.body = await MainView(ctx.$context);
|
ctx.body = MainView(ctx);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ router.delete("/:task_id", Middlewares.extractContext(), async (ctx) => {
|
|||||||
ctx.params.task_id
|
ctx.params.task_id
|
||||||
);
|
);
|
||||||
await task.remove(ctx.$context);
|
await task.remove(ctx.$context);
|
||||||
ctx.body = await MainView(ctx.$context);
|
ctx.body = MainView(ctx);
|
||||||
});
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user