-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
42 lines (31 loc) · 1.01 KB
/
Copy pathapp.js
File metadata and controls
42 lines (31 loc) · 1.01 KB
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
const express = require('express')
const { logger } = require('./middleware/logger.js')
const app = express()
app.set('view engine', 'ejs')
app.use(express.urlencoded({ extended: true }))
const PORT = 3000
app.use('/blog', express.static('public'))
app.use(logger)
app.get('/', (request, response) => {
response.render('index')
})
app.get('/about', (request, response) => {
response.sendFile('about.html', { root: 'public'})
})
app.get('/posts', (request, response) => {
response.sendFile('posts.html', { root: 'public'})
})
app.get('/contact', (request, response) => {
response.sendFile('contact.html', { root: 'public'})
})
app.get('/posts/:slug', (request, response) => {
const slug = request.params.slug
response.send(`You chose the post with the ID of ${slug}`)
})
app.post('/contact', (request, response) => {
console.log('Contact form submission: ', request.body)
response.sendFile('thankyou.html', {root: 'public'})
})
app.listen(PORT, () => {
console.log(`Started server on port ${PORT}`)
})