├── .gitignore ├── .travis.yml ├── README.md ├── lib └── index.js ├── package.json └── test ├── fixtures ├── app │ ├── bundle.js │ └── index.html ├── bundle.js └── index.html ├── helper ├── app │ ├── helper-about-nested.js │ ├── helper-about.js │ └── helper-index.js ├── helper-about-nested.js ├── helper-about.js └── helper-index.js └── index-test.js /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .idea/ 3 | .ipr 4 | .iws 5 | *~ 6 | ~* 7 | *.diff 8 | *.patch 9 | *.bak 10 | .DS_Store 11 | Thumbs.db 12 | .project 13 | .*proj 14 | .svn/ 15 | *.swp 16 | *.swo 17 | *.pyc 18 | *.pyo 19 | .build 20 | node_modules 21 | _site 22 | .cache 23 | dist 24 | coverage 25 | *.log 26 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | install: 4 | - npm install 5 | - npm install dora@0.4.x 6 | 7 | node_js: 8 | - "4" 9 | 10 | after_success: 11 | - npm run coveralls 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dora-plugin-browser-history 2 | 3 | dora plugin for [react-router](https://github.com/reactjs/react-router) browser history([#browserhistory](https://github.com/reactjs/react-router/blob/master/docs/guides/Histories.md#browserhistory)) 4 | 5 | [![NPM version](https://img.shields.io/npm/v/dora-plugin-browser-history.svg?style=flat)](https://npmjs.org/package/dora-plugin-browser-history) 6 | [![Build Status](https://img.shields.io/travis/dora-js/dora-plugin-browser-history.svg?style=flat)](https://travis-ci.org/dora-js/dora-plugin-browser-history) 7 | [![Coverage Status](https://img.shields.io/coveralls/dora-js/dora-plugin-browser-history.svg?style=flat)](https://coveralls.io/r/dora-js/dora-plugin-browser-history) 8 | 9 | 10 | ## Feature 11 | 12 | - support react-router `browserHistory` 13 | 14 | ## Install 15 | 16 | ```bash 17 | $ npm install dora-plugin-browser-history --save-dev 18 | ``` 19 | 20 | ## Usage 21 | 22 | ```javascript 23 | import { Router, Route, browserHistory } from 'react-router'; 24 | import Home from './Home'; 25 | import Setting from './Setting'; 26 | import Download from './Download'; 27 | 28 | ReactDom.render(( 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | ), document.getElementById('react-content')); 38 | ``` 39 | 40 | ```bash 41 | $ dora --plugins browser-history 42 | ``` 43 | 44 | ## Query 45 | 46 | Path of the index file 47 | 48 | ```bash 49 | $ dora --plugins browser-history?index=/example/entry.html 50 | ``` 51 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 'middleware': function() { 3 | var query = this.query; 4 | var middleware = require('connect-history-api-fallback')({ 5 | index: query.index || '/index.html', 6 | rewrites: query.rewrites, 7 | }); 8 | 9 | var noop = function() {}; 10 | 11 | return function* (next) { 12 | middleware(this, null, noop); 13 | yield next; 14 | }; 15 | }, 16 | }; 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dora-plugin-browser-history", 3 | "version": "0.2.0", 4 | "repository": { 5 | "type": "git", 6 | "url": "https://github.com/dora-js/dora-plugin-browser-history" 7 | }, 8 | "homepage": "https://github.com/dora-js/dora-plugin-browser-history", 9 | "author": "qiang.mou ", 10 | "license": "MIT", 11 | "main": "./lib", 12 | "scripts": { 13 | "test": "istanbul cover _mocha -- test/index-test.js -R spec --no-timeouts", 14 | "coveralls": "cat ./coverage/lcov.info | coveralls" 15 | }, 16 | "dependencies": { 17 | "connect-history-api-fallback": "~1.2.0" 18 | }, 19 | "devDependencies": { 20 | "coveralls": "^2.11.6", 21 | "dora": "0.4.x", 22 | "expect.js": "~0.3.1", 23 | "istanbul": "~0.4.2", 24 | "mocha": "^2.3.4", 25 | "phantomjs": "~2.1.3" 26 | }, 27 | "peerDependencies": { 28 | "dora": "0.4.x" 29 | }, 30 | "files": [ 31 | "lib", 32 | "package.json", 33 | "README.md" 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /test/fixtures/app/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | React 6 | 7 | 8 |
9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/fixtures/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | React 6 | 7 | 8 |
9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/helper/app/helper-about-nested.js: -------------------------------------------------------------------------------- 1 | var page = require('webpage').create(); 2 | page.open('http://localhost:23456/app/about/nested', function(status) { 3 | console.log("Status: " + status); 4 | phantom.exit(); 5 | }); -------------------------------------------------------------------------------- /test/helper/app/helper-about.js: -------------------------------------------------------------------------------- 1 | var page = require('webpage').create(); 2 | page.open('http://localhost:23456/app/about', function(status) { 3 | console.log("Status: " + status); 4 | phantom.exit(); 5 | }); -------------------------------------------------------------------------------- /test/helper/app/helper-index.js: -------------------------------------------------------------------------------- 1 | var page = require('webpage').create(); 2 | page.open('http://localhost:23456/app', function(status) { 3 | console.log("Status: " + status); 4 | phantom.exit(); 5 | }); -------------------------------------------------------------------------------- /test/helper/helper-about-nested.js: -------------------------------------------------------------------------------- 1 | var page = require('webpage').create(); 2 | page.open('http://localhost:12345/about/nested', function(status) { 3 | console.log("Status: " + status); 4 | phantom.exit(); 5 | }); -------------------------------------------------------------------------------- /test/helper/helper-about.js: -------------------------------------------------------------------------------- 1 | var page = require('webpage').create(); 2 | page.open('http://localhost:12345/about', function(status) { 3 | console.log("Status: " + status); 4 | phantom.exit(); 5 | }); -------------------------------------------------------------------------------- /test/helper/helper-index.js: -------------------------------------------------------------------------------- 1 | var page = require('webpage').create(); 2 | page.open('http://localhost:12345', function(status) { 3 | console.log("Status: " + status); 4 | phantom.exit(); 5 | }); -------------------------------------------------------------------------------- /test/index-test.js: -------------------------------------------------------------------------------- 1 | var dora = require('dora'); 2 | var expect = require('expect.js'); 3 | var join = require('path').join; 4 | var childProcess = require('child_process') 5 | var phantomjs = require('phantomjs') 6 | var binPath = phantomjs.path; 7 | 8 | describe('dora-plugin-browser-history', function(){ 9 | 10 | const oldCwd = process.cwd(); 11 | const cwd = join(__dirname, './fixtures'); 12 | 13 | describe('index with no query', function() { 14 | 15 | var helperIndexJs = join(__dirname, './helper/helper-index.js'); 16 | var helperAboutJs = join(__dirname, './helper/helper-about.js'); 17 | var helperAboutNestedJs = join(__dirname, './helper/helper-about-nested.js'); 18 | 19 | before(function(done) { 20 | process.chdir(cwd); 21 | dora({ 22 | port: 12345, 23 | plugins: [ 24 | '../../lib/index' 25 | ], 26 | cwd: cwd 27 | }); 28 | setTimeout(done, 1000); 29 | }); 30 | 31 | after(function() { 32 | process.chdir(oldCwd); 33 | }); 34 | 35 | it('GET index.html', function(done) { 36 | childProcess.execFile(binPath, [helperIndexJs], function(err, stdout, stderr) { 37 | expect(stdout.indexOf('success')).to.be.above(-1); 38 | done() 39 | }); 40 | }); 41 | 42 | it('GET /about 200', function(done) { 43 | childProcess.execFile(binPath, [helperAboutJs], function(err, stdout, stderr) { 44 | expect(stdout.indexOf('success')).to.be.above(-1); 45 | done() 46 | }); 47 | }); 48 | 49 | it('GET /about/nested 200', function(done) { 50 | childProcess.execFile(binPath, [helperAboutNestedJs], function(err, stdout, stderr) { 51 | expect(stdout.indexOf('success')).to.be.above(-1); 52 | done() 53 | }); 54 | }); 55 | }); 56 | 57 | describe('index with query', function() { 58 | 59 | var helperAppIndexJs = join(__dirname, './helper/app/helper-index.js'); 60 | var helperAppAboutJs = join(__dirname, './helper/app/helper-about.js'); 61 | var helperAppAboutNestedJs = join(__dirname, './helper/app/helper-about-nested.js'); 62 | 63 | before(function(done) { 64 | process.chdir(cwd); 65 | dora({ 66 | port: 23456, 67 | plugins: [ 68 | '../../lib/index?index=/app' 69 | ], 70 | cwd: cwd 71 | }); 72 | setTimeout(done, 1000); 73 | }); 74 | 75 | after(function() { 76 | process.chdir(oldCwd); 77 | }); 78 | 79 | it('GET /app/index.html', function(done) { 80 | childProcess.execFile(binPath, [helperAppIndexJs], function(err, stdout, stderr) { 81 | expect(stdout.indexOf('success')).to.be.above(-1); 82 | done() 83 | }); 84 | }); 85 | 86 | it('GET /app/about 200', function(done) { 87 | childProcess.execFile(binPath, [helperAppAboutJs], function(err, stdout, stderr) { 88 | expect(stdout.indexOf('success')).to.be.above(-1); 89 | done() 90 | }); 91 | }); 92 | 93 | it('GET /app/about/nested 200', function(done) { 94 | childProcess.execFile(binPath, [helperAppAboutNestedJs], function(err, stdout, stderr) { 95 | expect(stdout.indexOf('success')).to.be.above(-1); 96 | done() 97 | }); 98 | }); 99 | }); 100 | 101 | }); --------------------------------------------------------------------------------