Chapter 4,6: prettier updates and web framework samples
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
const express = require("express");
|
||||
const router = express.Router();
|
||||
|
||||
router.get("/:name?", function (req, res) {
|
||||
const title = "Express";
|
||||
const name = req.params.name;
|
||||
res.send(`
|
||||
<html>
|
||||
<head>
|
||||
<title> ${title} </title>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1> ${title} </h1>
|
||||
<p> Welcome to ${title}${name ? `, ${name}.` : ""} </p>
|
||||
<form method=POST action=data>
|
||||
Name: <input name=name> <input type=submit>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
`);
|
||||
});
|
||||
|
||||
router.post("/data", function (req, res) {
|
||||
res.redirect(`/${req.body.name}`);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user