-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
190 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# These are supported funding model platforms | ||
|
||
github: atian25 # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] | ||
patreon: atian25 # Replace with a single Patreon username | ||
open_collective: # Replace with a single Open Collective username | ||
ko_fi: # Replace with a single Ko-fi username | ||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel | ||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry | ||
liberapay: # Replace with a single Liberapay username | ||
issuehunt: # Replace with a single IssueHunt username | ||
otechie: # Replace with a single Otechie username | ||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] |
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,39 @@ | ||
name: Actions Release | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
Runner: | ||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
node-version: [12.x] | ||
|
||
steps: | ||
- name: Checkout Git Source | ||
uses: actions/checkout@v1 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: Install Dependencies | ||
run: | | ||
npm install | ||
- name: Continuous integration | ||
run: | | ||
npm run test | ||
- name: Release NPM Package | ||
run: | | ||
npm run semantic-release | ||
env: | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
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,33 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const fs = require('fs'); | ||
const { promisify } = require('util'); | ||
const rimraf = require('rimraf'); | ||
const writeFile = promisify(fs.writeFile); | ||
const mkdirp = promisify(fs.mkdir); | ||
const del = promisify(rimraf); | ||
|
||
module.exports = class AgentBootHook { | ||
constructor(agent) { | ||
this.agent = agent; | ||
this.logger = agent.logger; | ||
this.filePath = path.resolve(agent.config.rundir, agent.config.remoteConfig.savePath); | ||
} | ||
|
||
async willReady() { | ||
const { handler } = this.agent.config.remoteConfig; | ||
|
||
/* istanbul ignore else */ | ||
if (handler) { | ||
this.logger.info(`[RemoteConfig] loading remote config and save to ${this.filePath}`); | ||
const result = await handler(this.agent); | ||
await mkdirp(path.dirname(this.filePath), { recursive: true }); | ||
await writeFile(this.filePath, JSON.stringify(result || /* istanbul ignore next */{}, null, 2), 'utf-8'); | ||
} | ||
} | ||
|
||
async serverDidReady() { | ||
await del(this.filePath); | ||
} | ||
}; |
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,26 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const fs = require('fs'); | ||
const extend = require('extend2'); | ||
|
||
module.exports = class AppBootHook { | ||
constructor(app) { | ||
this.app = app; | ||
this.logger = app.logger; | ||
} | ||
|
||
configWillLoad() { | ||
const { savePath } = this.app.config.remoteConfig; | ||
const filePath = path.resolve(this.app.config.rundir, savePath); | ||
|
||
this.logger.info(`[RemoteConfig] loading remote config from ${filePath}`); | ||
|
||
try { | ||
const result = JSON.parse(fs.readFileSync(filePath, 'utf-8')); | ||
extend(true, this.app.config, result); | ||
} catch (err) { /* istanbul ignore next */ | ||
this.logger.warn(`[RemoteConfig] load ${filePath} fail: ${err.message}`); | ||
} | ||
} | ||
}; |
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
11 changes: 0 additions & 11 deletions
11
test/fixtures/apps/remote-config-test/app/controller/home.js
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
test/fixtures/apps/remote-config-test/config/config.default.js
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,17 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const assertFile = require('assert-file'); | ||
|
||
module.exports = class AppBootHook { | ||
constructor(app) { | ||
this.app = app; | ||
} | ||
|
||
configDidLoad() { | ||
const { savePath } = this.app.config.remoteConfig; | ||
const filePath = path.resolve(this.app.config.rundir, savePath); | ||
|
||
assertFile(filePath); | ||
} | ||
}; |
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,27 @@ | ||
'use strict'; | ||
|
||
exports.keys = '123456'; | ||
|
||
exports.foo = 'foo'; | ||
|
||
exports.sub = { | ||
a: 'a', | ||
}; | ||
|
||
exports.remoteConfig = { | ||
async handler(agent) { | ||
// fetch remote config | ||
const { data } = await agent.curl('https://github.com/atian25/egg-remote-config/raw/master/package.json', { | ||
dataType: 'json', | ||
contentType: 'json', | ||
followRedirect: true, | ||
}); | ||
|
||
return { | ||
foo: data.name, | ||
sub: { | ||
a: 'b', | ||
}, | ||
}; | ||
}, | ||
}; |
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 @@ | ||
'use strict'; | ||
|
||
exports.static = false; |
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,4 @@ | ||
{ | ||
"name": "example", | ||
"version": "0.0.1" | ||
} |
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 |
---|---|---|
@@ -1,23 +1,27 @@ | ||
'use strict'; | ||
|
||
const mock = require('egg-mock'); | ||
const assert = require('assert'); | ||
const asserFile = require('assert-file'); | ||
const path = require('path'); | ||
const { rimraf } = require('mz-modules'); | ||
|
||
describe('test/remote-config.test.js', () => { | ||
let app; | ||
before(() => { | ||
before(async () => { | ||
app = mock.app({ | ||
baseDir: 'apps/remote-config-test', | ||
baseDir: 'example', | ||
}); | ||
return app.ready(); | ||
await rimraf(path.join(__dirname, 'fixtures/example/run')); | ||
await app.ready(); | ||
}); | ||
|
||
after(() => app.close()); | ||
afterEach(mock.restore); | ||
|
||
it('should GET /', () => { | ||
return app.httpRequest() | ||
.get('/') | ||
.expect('hi, remoteConfig') | ||
.expect(200); | ||
it('should works', () => { | ||
assert(app.config.foo === 'egg-remote-config'); | ||
assert(app.config.sub.a === 'b'); | ||
asserFile.fail(path.join(app.config.rundir, 'remote_config.json')); | ||
}); | ||
}); |