Skip to content

Commit 591b2ac

Browse files
committed
Add files from existing repo, udemy
1 parent 3aeaa6e commit 591b2ac

12 files changed

Lines changed: 342 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Exploring templating engines - Pug, Handlebars, EJS
33

44
- Done as a part [Node.js - The Complete Guide (Max Schwarzmuller) @Udemy](https://www.udemy.com/course/nodejs-the-complete-guide/)
55
- Notes - https://github.com/sanjar-notes/nodejs-notes
6+
- Initial code was inherited from [an existing project](https://github.com/exemplar-codes/traditional-web-app-express), with minor changes provided by the course.

app.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const path = require('path');
2+
3+
const express = require('express');
4+
const bodyParser = require('body-parser');
5+
6+
const app = express();
7+
8+
const adminData = require('./routes/admin');
9+
const shopRoutes = require('./routes/shop');
10+
11+
app.use(bodyParser.urlencoded({extended: false}));
12+
app.use(express.static(path.join(__dirname, 'public')));
13+
14+
app.use('/admin', adminData.routes);
15+
app.use(shopRoutes);
16+
17+
app.use((req, res, next) => {
18+
res.status(404).sendFile(path.join(__dirname, 'views', '404.html'));
19+
});
20+
21+
app.listen(3000);

package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "nodejs-complete-guide",
3+
"version": "1.0.0",
4+
"description": "Complete Node.js Guide",
5+
"main": "app.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"start": "nodemon app.js",
9+
"start-server": "node app.js"
10+
},
11+
"author": "Maximilian Schwarzmüller",
12+
"license": "ISC",
13+
"devDependencies": {
14+
"nodemon": "^1.18.3"
15+
},
16+
"dependencies": {
17+
"body-parser": "^1.18.3",
18+
"express": "^4.16.3"
19+
}
20+
}

public/css/forms.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.form-control {
2+
margin: 1rem 0;
3+
}
4+
5+
.form-control label,
6+
.form-control input {
7+
display: block;
8+
width: 100%;
9+
margin-bottom: 0.25rem;
10+
}
11+
12+
.form-control input {
13+
border: 1px solid #a1a1a1;
14+
font: inherit;
15+
border-radius: 2px;
16+
}
17+
18+
.form-control input:focus {
19+
outline-color: #00695c;
20+
}

public/css/main.css

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
@import url('https://fonts.googleapis.com/css?family=Open+Sans:400,700');
2+
3+
* {
4+
box-sizing: border-box;
5+
}
6+
7+
body {
8+
padding: 0;
9+
margin: 0;
10+
font-family: 'Open Sans', sans-serif;
11+
}
12+
13+
main {
14+
padding: 1rem;
15+
margin: auto;
16+
}
17+
18+
.main-header {
19+
width: 100%;
20+
height: 3.5rem;
21+
background-color: #00695c;
22+
padding: 0 1.5rem;
23+
}
24+
25+
.main-header__nav {
26+
height: 100%;
27+
display: flex;
28+
align-items: center;
29+
}
30+
31+
.main-header__item-list {
32+
list-style: none;
33+
margin: 0;
34+
padding: 0;
35+
display: flex;
36+
}
37+
38+
.main-header__item {
39+
margin: 0 1rem;
40+
padding: 0;
41+
}
42+
43+
.main-header__item a {
44+
text-decoration: none;
45+
color: white;
46+
}
47+
48+
.main-header__item a:hover,
49+
.main-header__item a:active,
50+
.main-header__item a.active {
51+
color: #ffeb3b;
52+
}
53+
54+
.grid {
55+
display: flex;
56+
flex-wrap: wrap;
57+
justify-content: space-around;
58+
align-items: stretch;
59+
}
60+
61+
.card {
62+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
63+
}
64+
65+
.card__header,
66+
.card__content {
67+
padding: 1rem;
68+
}
69+
70+
.card__header h1,
71+
.card__content h1,
72+
.card__content h2,
73+
.card__content p {
74+
margin: 0;
75+
}
76+
77+
.card__image {
78+
width: 100%;
79+
}
80+
81+
.card__image img {
82+
width: 100%;
83+
}
84+
85+
.card__actions {
86+
padding: 1rem;
87+
text-align: center;
88+
}
89+
90+
.card__actions button,
91+
.card__actions a {
92+
margin: 0 0.25rem;
93+
}
94+
95+
.btn {
96+
font: inherit;
97+
border: 1px solid #00695c;
98+
color: #00695c;
99+
background: white;
100+
border-radius: 3px;
101+
cursor: pointer;
102+
}
103+
104+
.btn:hover,
105+
.btn:active {
106+
background-color: #00695c;
107+
color: white;
108+
}

public/css/product.css

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.product-form {
2+
width: 20rem;
3+
max-width: 90%;
4+
margin: auto;
5+
}
6+
7+
.product-item {
8+
width: 20rem;
9+
max-width: 95%;
10+
}
11+
12+
.product__title {
13+
font-size: 1.2rem;
14+
text-align: center;
15+
}
16+
17+
.product__price {
18+
text-align: center;
19+
color: #4d4d4d;
20+
margin-bottom: 0.5rem;
21+
}
22+
23+
.product__description {
24+
text-align: center;
25+
}

routes/admin.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const path = require('path');
2+
3+
const express = require('express');
4+
5+
const rootDir = require('../util/path');
6+
7+
const router = express.Router();
8+
9+
const products = [];
10+
11+
// /admin/add-product => GET
12+
router.get('/add-product', (req, res, next) => {
13+
res.sendFile(path.join(rootDir, 'views', 'add-product.html'));
14+
});
15+
16+
// /admin/add-product => POST
17+
router.post('/add-product', (req, res, next) => {
18+
products.push({ title: req.body.title });
19+
res.redirect('/');
20+
});
21+
22+
exports.routes = router;
23+
exports.products = products;

routes/shop.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const path = require('path');
2+
3+
const express = require('express');
4+
5+
const rootDir = require('../util/path');
6+
const adminData = require('./admin');
7+
8+
const router = express.Router();
9+
10+
router.get('/', (req, res, next) => {
11+
console.log('shop.js', adminData.products);
12+
res.sendFile(path.join(rootDir, 'views', 'shop.html'));
13+
});
14+
15+
module.exports = router;

util/path.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const path = require('path');
2+
3+
module.exports = path.dirname(process.mainModule.filename);

views/404.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8+
<title>Page Not Found</title>
9+
<link rel="stylesheet" href="/css/main.css">
10+
</head>
11+
12+
<body>
13+
<header class="main-header">
14+
<nav class="main-header__nav">
15+
<ul class="main-header__item-list">
16+
<li class="main-header__item"><a class="active" href="/">Shop</a></li>
17+
<li class="main-header__item"><a href="/admin/add-product">Add Product</a></li>
18+
</ul>
19+
</nav>
20+
</header>
21+
<h1>Page Not Found!</h1>
22+
</body>
23+
24+
</html>

0 commit comments

Comments
 (0)