Skip to content

Commit

Permalink
fix fauxton server for module
Browse files Browse the repository at this point in the history
 - use native node methods instead of custom solutions

PR: #613
PR-URL: #613
Reviewed-By: Benjamin Keen <[email protected]>
  • Loading branch information
robertkowalski committed Jan 20, 2016
1 parent 1de7efa commit 16a8143
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
6 changes: 4 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
/*jslint node: true */
"use strict";

const path = require('path');

module.exports = function (grunt) {
var helper = require('./tasks/helper.js'),
initHelper = helper.init(grunt),
Expand Down Expand Up @@ -325,7 +327,7 @@ module.exports = function (grunt) {
options: {
afterEach: function (fileChanges) {
// replace the REQUIREJS_FILE placeholder with the actual filename
var newFilename = fileChanges.newPath.match(/[^\/]+$/)[0];
const newFilename = path.basename(fileChanges.newPath);
config.template.release.variables.requirejs = config.template.release.variables.requirejs.replace(/REQUIREJS_FILE/, newFilename);
}
}
Expand All @@ -336,7 +338,7 @@ module.exports = function (grunt) {
options: {
afterEach: function (fileChanges) {
// replace the CSS_FILE placeholder with the actual filename
var newFilename = fileChanges.newPath.match(/[^\/]+$/)[0];
const newFilename = path.basename(fileChanges.newPath);
config.template.release.variables.css = config.template.release.variables.css.replace(/CSS_FILE/, newFilename);
}
}
Expand Down
14 changes: 4 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,10 @@ module.exports = function (options) {
.pipe(res);
}

var fileTypes = ['js', 'css', 'png', 'swf', 'eot', 'woff', 'svg', 'ttf', 'swf'];
var fileTypes = ['.js', '.css', '.png', '.swf', '.eot', '.woff', '.svg', '.ttf', '.swf'];

function isFile (url) {
var arr = url.split('.');

if (arr.length < 2) {
return false;
}

return _.contains(fileTypes, arr[1]);
return _.contains(fileTypes, path.extname(url));
}

// create proxy to couch for all couch requests
Expand All @@ -46,7 +40,7 @@ module.exports = function (options) {
});

http.createServer(function (req, res) {
var isDocLink = /_utils\/docs/.test(req.url) ? true : false;
var isDocLink = /_utils\/docs/.test(req.url);
var url = req.url.split(/\?v=|\?noCache/)[0].replace('_utils', '');
var accept = req.headers.accept.split(',');

Expand All @@ -59,7 +53,7 @@ module.exports = function (options) {
if (url === '/' && accept[0] !== 'application/json') {
// serve main index file from here
return sendFile(req, res, path.join(dist_dir, 'index.html'));
} else if (isFile(url) && !isDocLink ) {
} else if (isFile(url) && !isDocLink) {
return sendFile(req, res, path.join(dist_dir, url));
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
"react-tools": "^0.12.0",
"request": "^2.54.0",
"requirejs": "^2.1.22",
"semver": "^5.1.0",
"send": "~0.1.1",
"uglify-js": "^2.6.1",
"underscore": "~1.4.2",
"url": "~0.7.9",
"urls": "~0.0.3"
},

"scripts": {
"stylecheck": "eslint --ext=js,jsx .",
"build:less:debug": "mkdirp ./dist/debug/dashboard.assets/css && node ./build-helper/less.js dist/debug/dashboard.assets/css/index.css",
Expand All @@ -62,7 +62,7 @@
"dev": "grunt dev",
"nightwatch": "grunt nightwatch",
"start": "node ./bin/fauxton",
"postinstall": "grunt release"
"postinstall": "node version-check.js && grunt release"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion settings.json.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"src": "assets/index.underscore",
"dest": "dist/debug/index.html",
"variables": {
"requirejs": "./js/REQUIREJS_FILE",
"requirejs": "./dashboard.assets/js/REQUIREJS_FILE",
"css": "./dashboard.assets/css/CSS_FILE",
"base": null
},
Expand Down
9 changes: 9 additions & 0 deletions version-check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var semver = require('semver');

var version = process.version.replace(/^v/, '');

if (!semver.satisfies(version, '>=4')) {
console.error('Error:');
console.error('Fauxton needs Node 4 or greater to work');
process.exit(1);
}

0 comments on commit 16a8143

Please sign in to comment.