Created
December 28, 2016 21:31
-
-
Save mfazekas/eba2f2076076fe95f404f6ce66b3ed96 to your computer and use it in GitHub Desktop.
start a global express server for mirage in fastboot instance-initializers/fastboot/start-mirage.js
This file contains hidden or 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
| /* instance-initializers/fastboot/start-mirage.js */ | |
| /*global process*/ | |
| import { startMirage } from 'percy-web/initializers/ember-cli-mirage'; | |
| import config from '../../config/environment'; | |
| function startFastBootMirage() { | |
| if (config['ember-cli-mirage'] && config['ember-cli-mirage'].fastbootGlobal) { | |
| let port = config['ember-cli-mirage'].fastbootGlobal.port; | |
| return startMirage({ | |
| environment: 'development', | |
| modulePrefix:'fastboot-mirage-test', | |
| 'ember-cli-mirage': {serverOptions: {express: {port}}}}); | |
| } | |
| } | |
| function storeServerForRestartOnLiveReload(server) { | |
| if (typeof FastBoot !== 'undefined') { | |
| let express = FastBoot.require('express'); | |
| express.mirageServer = server; | |
| } | |
| } | |
| function shutdownOldServerIfLiveReload() { | |
| if (typeof FastBoot !== 'undefined') { | |
| let express = FastBoot.require('express'); | |
| if (express.mirageServer) { | |
| express.mirageServer.shutdown(); | |
| } | |
| } | |
| } | |
| shutdownOldServerIfLiveReload(); | |
| var server = startFastBootMirage(); | |
| storeServerForRestartOnLiveReload(server); | |
| export default { | |
| name: "start-mirage", | |
| initialize: function(/*instance*/) { } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment