-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
36 lines (27 loc) · 874 Bytes
/
Copy pathapp.js
File metadata and controls
36 lines (27 loc) · 874 Bytes
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
const express = require('express');
const path = require('path');
app.use(express.static(path.join(__dirname, 'stylesheets')));
const app = express();
const hostname = '127.0.0.1'; //localhost
const port = 8005;
app.use(express.static('views'));
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'views', 'index.html'));
});
app.get('/about', (req, res) => {
res.sendFile(path.join(__dirname, 'views', 'about.html'));
});
app.get('/contact', (req, res) => {
res.sendFile(path.join(__dirname, 'views', 'contact.html'));
});
app.get('/contact/submit', (req, res) => {
const { name, message } = req.query;
res.send(`
<h1>Thank you, ${name}!</h1>
<p>We have received your message: "${message}"</p>
<a href="/">Go Back to Home</a>
`);
});
app.listen(PORT, () => {
console.log(`Server is running on http://hostname:${port}/`);
});