Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/egg.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,23 @@ class EggCore extends KoaApplication {
constructor(options = {}) {
options.baseDir = options.baseDir || process.cwd();
options.type = options.type || 'application';
if (typeof options.pathToRegexpModule === 'string') {
const pathToRegexpModule = options.pathToRegexpModule || process.env.EGG_OPTIONS_PATH_TO_REGEXP_MODULE;
if (typeof pathToRegexpModule === 'string') {
/**
* Usage:
*
* ```js
* const app = new Application({
* pathToRegexpModule: '/path/to/path-to-regexp-v8',
* });
* ```
*
* Or you can use `EGG_OPTIONS_PATH_TO_REGEXP_MODULE` environment variable.
* ```bash
* EGG_OPTIONS_PATH_TO_REGEXP_MODULE=/path/to/path-to-regexp-v8 npm start
* ```
*/
options.pathToRegexpModule = require(options.pathToRegexpModule);
options.pathToRegexpModule = require(pathToRegexpModule);
}

assert(typeof options.baseDir === 'string', 'options.baseDir required, and must be a string');
Expand Down
6 changes: 5 additions & 1 deletion test/utils/router-with-pathToRegexpModule.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
const assert = require('assert');
const request = require('supertest');
const mm = require('mm');
const utils = require('../utils');

describe('test/utils/router-with-pathToRegexpModule.test.js', () => {
afterEach(mm.restore);

let app;
before(() => {
app = utils.createApp('router-app-with-pathToRegexpModule', {
Expand Down Expand Up @@ -329,8 +332,9 @@ describe('test/utils/router-with-pathToRegexpModule.test.js', () => {
});
});

describe('router middleware', () => {
describe('set by env: EGG_OPTIONS_PATH_TO_REGEXP_MODULE', () => {
before(() => {
mm(process.env, 'EGG_OPTIONS_PATH_TO_REGEXP_MODULE', 'path-to-regexp-v8');
app = utils.createApp('router-in-app');
app.loader.loadAll();
return app.ready();
Expand Down
Loading