Skip to content

Commit 48f9e1a

Browse files
committed
Serve static from static folder
1 parent e9624f1 commit 48f9e1a

29 files changed

Lines changed: 10 additions & 60 deletions

Lesson03/exercise_004/css/store_with_header.css

Lines changed: 0 additions & 53 deletions
This file was deleted.

Lesson03/exercise_004/html/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<html>
22
<head>
33
<link rel="stylesheet" type="text/css" href="css/semantic.min.css" />
4-
<link rel="stylesheet" type="text/css" href="css/store_with_header.css" />
4+
<link rel="stylesheet" type="text/css" href="css/store.css" />
55
</head>
66
<body>
77
<section>
@@ -13,7 +13,7 @@ <h1 class="title">Welcome to Fresh Products Store!</h1>
1313
<div class="content">
1414
<a class="header">{{name}}</a>
1515
<div class="meta">
16-
<span>${{price}} / {{unit}}</span>
16+
<span>${{currency price}} / {{unit}}</span>
1717
</div>
1818
<div class="description">{{description}}</div>
1919
<div class="extra">
@@ -27,4 +27,4 @@ <h1 class="title">Welcome to Fresh Products Store!</h1>
2727
</div>
2828
</section>
2929
</body>
30-
</html>
30+
</html>

Lesson03/exercise_004/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ const mime = require('mime');
55
const path = require('path');
66
const url = require('url');
77

8-
const currentDir = path.resolve('./');
9-
console.log(`Running from ${currentDir}`);
8+
const staticDir = path.resolve('./static');
9+
console.log(`Static resources from ${staticDir}`);
1010

1111
const data = fs.readFileSync('products.json');
1212
const products = JSON.parse(data.toString());
1313
console.log(`Loaded ${products.length} products...`);
1414

15+
handlebars.registerHelper('currency', (number) => number.toFixed(2));
16+
1517
function handleNotFound(response) {
1618
response.writeHead(404);
1719
response.end();
@@ -26,8 +28,9 @@ function handleProductsPage(requestUrl, response) {
2628
}
2729

2830
function handleStaticFile(pathname, response) {
29-
const fullPath = path.resolve(pathname.substr(1));
30-
if (!fullPath.startsWith(currentDir)) {
31+
// For security reasons, only serve files from static directory
32+
const fullPath = path.resolve(`static${pathname}`);
33+
if (!fullPath.startsWith(staticDir)) {
3134
return handleNotFound(response);
3235
}
3336

File renamed without changes.
File renamed without changes.

Lesson03/exercise_004/css/themes/default/assets/fonts/icons.woff renamed to Lesson03/exercise_004/static/css/themes/default/assets/fonts/icons.woff

File renamed without changes.

Lesson03/exercise_004/css/themes/default/assets/fonts/icons.woff2 renamed to Lesson03/exercise_004/static/css/themes/default/assets/fonts/icons.woff2

File renamed without changes.

Lesson03/exercise_004/images/brick-wall-1245825_1920.jpg renamed to Lesson03/exercise_004/static/images/brick-wall-1245825_1920.jpg

File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)