/
alexrodionov
/
node
Обзор
Документация
Войти
/
alexrodionov
/
node
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
ch06/10-basic-form-processing.js
24 строки
860 B
Ethan Brown
Initial commit. Drafts through Chapter 12; still a lot of work to do!
03 июн 2019, 02:36
03 июн 2019, 02:36
e7c405f
Код
Авторство
О чём код?
const express = require('express') const expressHandlebars = require('express-handlebars') const bodyParser = require('body-parser') const app = express() // the following is needed to use views app.engine('handlebars', expressHandlebars({ defaultLayout: 'main' })) app.set('view engine', 'handlebars') // this is necessary to parse form responses app.use(bodyParser.urlencoded({ extended: false })) app.get('/thank-you', (req, res) => res.render('10-thank-you')) // see the views/10-home.hbs file for the contents of this view app.get('*', (req, res) => res.render('10-home')) app.post('/process-contact', (req, res) => { console.log(`received contact from ${req.body.name} <${req.body.email}>`) res.redirect(303, '/thank-you') }) const port = process.env.PORT || 3000 app.listen(port, () => console.log(`\nnavigate to http://localhost:${port}\n`))