🌶🍲 Checkpoint

./views/room.handlebars:530995/365
./server.js:530995/486
./views/join.handlebars:530995/26
./package.json:530995/1360
This commit is contained in:
Glitch (hello-express) 2020-04-09 10:30:15 +00:00
parent c2acb83882
commit 0c20db100b
5 changed files with 23 additions and 16 deletions

View File

@ -11,7 +11,8 @@
},
"dependencies": {
"express": "^4.17.1",
"express-handlebars": "^4.0.3"
"express-handlebars": "^4.0.3",
"body-parser": "^1.19.0"
},
"engines": {
"node": "12.x"

View File

@ -1,7 +1,13 @@
const express = require("express");
var exphbs = require('express-handlebars');
const exphbs = require('express-handlebars');
const bodyParser = require('body-parser')
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
app.engine('handlebars', exphbs());
app.set('view engine', 'handlebars');
@ -12,7 +18,11 @@ app.get("/:roomId/join", (request, response) => {
});
app.post("/:roomId/join", (request, response) => {
response.render('room', {layout: false, room: request.params.roomId});
response.render('room', {
layout: false,
room: request.params.roomId,
name: request.body.name
});
});
const listener = app.listen(process.env.PORT, () => {

View File

@ -1,4 +1,5 @@
dependencies:
body-parser: 1.19.0
express: 4.17.1
express-handlebars: 4.0.3
packages:
@ -562,5 +563,6 @@ registry: 'https://registry.npmjs.org/'
shrinkwrapMinorVersion: 9
shrinkwrapVersion: 3
specifiers:
body-parser: ^1.19.0
express: ^4.17.1
express-handlebars: ^4.0.3

View File

@ -20,7 +20,7 @@
<p>Tell me your (team) name:</p>
<form>
<form method="POST">
<label>
Name
<input name="name" type="text" maxlength="100" required>

View File

@ -12,21 +12,15 @@
</head>
<body>
<header>
<h1>Join {{room}}</h1>
<h1>{{room}}</h1>
</header>
<main>
<h2>Oh hi,</h2>
<p>Tell me your (team) name:</p>
<form>
<label>
Name
<input name="name" type="text" maxlength="100" required>
</label>
<button type="submit" id="submit-name">Submit</button>
</form>
<h2>Oh hi, {{name}}</h2>
<button id="buzzer">
BUZZ
</button>
</main>
</body>
</html>