-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decouple SPA client from base project
- Loading branch information
Showing
13 changed files
with
137 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"routerPipeline": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// Simple clone that only considers Objects and Arrays | ||
// | ||
module.exports = function clone (item) { | ||
if ( Array.isArray(item) ) { | ||
return item.slice().map(clone) | ||
} | ||
else if ( isObject(item) ) { | ||
var cloned = {} | ||
for (var prop in item) { | ||
cloned[prop] = clone( item[prop] ) | ||
} | ||
return cloned | ||
} | ||
else { | ||
return item | ||
} | ||
} | ||
|
||
var isObject = (item) => Object.prototype.toString.call(item) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var lib = require('../../lib') | ||
|
||
|
||
module.exports = function configClient (vfs, baseConfig, moduleArgs) { | ||
if ( moduleArgs.length >= 2 ) { | ||
throw new lib.errors.ModuleError('Module `spa` only takes 1 argument') | ||
} | ||
|
||
var serverConfig = lib.clone(baseConfig.server) | ||
|
||
serverConfig["spa"] = { | ||
"browserify": { | ||
"external": [] | ||
} | ||
} | ||
|
||
serverConfig.routerPipeline.unshift('./config/client-bundles.js') | ||
serverConfig.routerPipeline.push('./config/catch-all-index-page.js') | ||
|
||
var config = { | ||
dependencies: { | ||
"browserify-middleware": "^7.1.0", | ||
}, | ||
server: serverConfig, | ||
} | ||
|
||
config.installs = Object.keys(config.dependencies) | ||
|
||
return config | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
base-template/client/public/index.html → ...les/spa/template/client/public/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
modules/spa/template/server/config/catch-all-index-page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
var Path = require('path') | ||
var clientConfig = require('./client-bundles') | ||
|
||
|
||
exports.mount = function clientBundleSetup (router) { | ||
// | ||
// The Catch-all Route | ||
// This is for supporting browser history pushstate. | ||
// NOTE: Make sure this route is always LAST in routerPipeline. | ||
// | ||
router.get('/*', function(req, res){ | ||
res.sendFile( Path.resolve(clientConfig.getAssetFolder(), './index.html') ) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
var express = require('express') | ||
var browserify = require('browserify-middleware') | ||
var Path = require('path') | ||
|
||
var assetFolder = Path.resolve(__dirname, '../../client/public') | ||
|
||
|
||
exports.mount = function clientBundleSetup (router) { | ||
// | ||
// Provide browserified files at specified paths | ||
// | ||
router.get('/vendor-bundle.js', browserify(CONFIG.spa.browserify.external)) | ||
|
||
router.get('/app-bundle.js', browserify('./client/index.js', CONFIG.spa.browserify)) | ||
|
||
// | ||
// Static assets (html, etc.) | ||
// | ||
router.use(express.static(assetFolder)) | ||
} | ||
|
||
exports.getAssetFolder = function () { return assetFolder } |