nodejs-app-first-dockerfile
This commit is contained in:
11
Dockerfile
Normal file
11
Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
||||
FROM node
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY . /app
|
||||
|
||||
RUN npm install
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
CMD ["node", "server.js"]
|
||||
12
package.json
Normal file
12
package.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "docker-complete",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "server.js",
|
||||
"author": "Maximilian Schwarzmüller / Academind GmbH",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"express": "^4.17.1",
|
||||
"body-parser": "1.19.0"
|
||||
}
|
||||
}
|
||||
48
public/styles.css
Normal file
48
public/styles.css
Normal file
@@ -0,0 +1,48 @@
|
||||
html {
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
section,
|
||||
form {
|
||||
padding: 1rem;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
|
||||
margin: 2rem auto;
|
||||
max-width: 40rem;
|
||||
}
|
||||
|
||||
.form-control {
|
||||
margin: 0.5rem 0;
|
||||
}
|
||||
|
||||
input {
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
input,
|
||||
label {
|
||||
display: block;
|
||||
}
|
||||
|
||||
label {
|
||||
font-weight: bold;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
button {
|
||||
background-color: #2f005a;
|
||||
border: 1px solid #2f005a;
|
||||
color: white;
|
||||
cursor: pointer;
|
||||
padding: 0.5rem 1.5rem;
|
||||
}
|
||||
|
||||
button:hover,
|
||||
button:active {
|
||||
background-color: #50005a;
|
||||
border-color: #50005a;
|
||||
}
|
||||
46
server.js
Normal file
46
server.js
Normal file
@@ -0,0 +1,46 @@
|
||||
const express = require('express');
|
||||
const bodyParser = require('body-parser');
|
||||
|
||||
const app = express();
|
||||
|
||||
let userGoal = 'Learn Docker!';
|
||||
|
||||
app.use(
|
||||
bodyParser.urlencoded({
|
||||
extended: false,
|
||||
})
|
||||
);
|
||||
|
||||
app.use(express.static('public'));
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.send(`
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<section>
|
||||
<h2>My Course Goal</h2>
|
||||
<h3>${userGoal}</h3>
|
||||
</section>
|
||||
<form action="/store-goal" method="POST">
|
||||
<div class="form-control">
|
||||
<label>Course Goal</label>
|
||||
<input type="text" name="goal">
|
||||
</div>
|
||||
<button>Set Course Goal</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
`);
|
||||
});
|
||||
|
||||
app.post('/store-goal', (req, res) => {
|
||||
const enteredGoal = req.body.goal;
|
||||
console.log(enteredGoal);
|
||||
userGoal = enteredGoal;
|
||||
res.redirect('/');
|
||||
});
|
||||
|
||||
app.listen(80);
|
||||
Reference in New Issue
Block a user