Skip to content
This repository was archived by the owner on Sep 10, 2022. It is now read-only.

Commit 42aa83d

Browse files
author
Matt Gaunt
committed
Fixing up the remaning issues with some comments
1 parent 6bc01a1 commit 42aa83d

File tree

7 files changed

+24
-19
lines changed

7 files changed

+24
-19
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "app-shell",
3-
"version": "0.1.148",
3+
"version": "0.1.150",
44
"private": true,
55
"license": "Apache",
66
"engines": {

server/app.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
'use strict';
22

3+
/**
4+
*
5+
* The structure of this node server is the following:
6+
* 1.) server-controller starts an express server which defines the static
7+
* content, port number and sets up handle bars to use the views and layouts
8+
* 2.) URLs are then routed by defining a url and calling addEndpoint(). On
9+
* requests to a matching url the onRequest() method is called in the
10+
* passed in controller (i.e. StaticPageController)
11+
*
12+
*/
13+
314
var serverController = require('./controllers/server-controller');
415
var StaticPageController = require('./controllers/static-page-controller');
516

server/controllers/server-controller.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,24 @@ function ServerController() {
1616
}
1717

1818
ServerController.prototype.setUpServer = function(app) {
19+
// Set up the use of handle bars and set the path for views and layouts
1920
app.set('views', path.join(__dirname, '/../views'));
2021
app.engine('handlebars', exphbs({
2122
defaultLayout: 'default',
2223
layoutsDir: path.join(__dirname, '/../layouts')
2324
}));
2425
app.set('view engine', 'handlebars');
2526

26-
// Should be set POST login auth
27-
app.use('/manifest.json',
28-
express.static(path.join(__dirname + '/../../dist/manifest.json')));
29-
app.use('/favicon.ico',
30-
express.static(path.join(__dirname + '/../../dist/favicon.ico')));
31-
app.use('/sw.js',
32-
express.static(path.join(__dirname + '/../../dist/scripts/sw.js')));
33-
app.use('/styles',
34-
express.static(path.join(__dirname + '/../../dist/styles')));
35-
app.use('/images',
36-
express.static(path.join(__dirname + '/../../dist/images')));
37-
app.use('/scripts',
38-
express.static(path.join(__dirname + '/../../dist/scripts')));
39-
app.use('/third_party',
40-
express.static(path.join(__dirname + '/../../dist/third_party')));
27+
// Define static assets path - i.e. styles, scripts etc.
28+
app.use('/',
29+
express.static(path.join(__dirname + '/../../dist/')));
4130

4231
console.log('Starting server on 3123');
4332
return app.listen('3123');
4433
};
4534

4635
ServerController.prototype.addEndpoint = function(endpoint, controller) {
36+
// Add the endpoint and call the onRequest method when a request is made
4737
this.getExpressApp().get(endpoint, function(req, res) {
4838
controller.onRequest(req, res);
4939
});

server/controllers/static-page-controller.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ function prepareData(config) {
1212
var flattenedStyles = '';
1313
var pathPrefix = '/../../dist/';
1414
config.inlineStyles.forEach(function(file) {
15-
flattenedStyles += fs.readFileSync(path.resolve(__dirname) + pathPrefix + file);
15+
flattenedStyles += fs.readFileSync(path.resolve(__dirname) +
16+
pathPrefix + file);
1617
});
18+
1719
// Replace array with flattened string of content
1820
config.inlineStyles = flattenedStyles;
1921
return config;
20-
};
22+
}
2123

24+
// This method looks at the request path and renders the appropriate handlebars
25+
// template
2226
StaticPageController.prototype.onRequest = function(req, res) {
2327
switch (req.path) {
2428
case '/':

server/layouts/default.handlebars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<link rel="manifest" href="/manifest.json">
1212
<link rel="icon" href="/images/chrome-touch-icon-192x192.png" sizes="192x192" type="image/png">
1313

14-
<style>{{{inlineStyles}}}</style>
14+
<style type="text/css">{{{inlineStyles}}}</style>
1515
</head>
1616
<body>
1717

File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)