New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extract the starting functionality into an exported class. #3815
Conversation
}; | ||
|
||
// To be called after `stop` | ||
GhostServer.prototype.hammertime = function () { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This is pretty damned awesome 🎈 unfortunately I merged another big refactoring PR that got in first, and it has caused a conflict. If you have a minute to rebase it would be much appreciated. |
I can't get to it right away, but I'll look at getting that sorted out On Tue, Aug 19, 2014 at 10:30 AM, Hannah Wolfe notifications@github.com
|
Oh aye no rush :) |
Ooh, looks like you used merge rather than rebase? Rebasing should still leave you with just a single commit on the PR rather than collecting up other bits and pieces. No worries as I should be able to fix it up, but I recommend using rebase for updating PRs from master. |
I'm pretty sure I did a rebase initially, but git wouldn't let me |
@JoshWillik your call, it's your PR :) I'm happy to take a look if it's gotten too messy. Top tip: no matter what, you can always update the PR by pushing a branch with the same name as the original branch the PR was made from ;) |
Not totally sure if I'm reading this correctly. |
Indeed! In fact if it all goes totally wonk, you can make a make a new branch, cherry pick, delete the old branch, rename your new branch to have the same name and push with a |
Ah excellent. It's good to know that PRs are so versatile. — On Wed, Aug 20, 2014 at 3:31 PM, Hannah Wolfe notifications@github.com
|
713d8df
to
569ff60
Compare
this is rawsome |
569ff60
to
2127e0a
Compare
I'm fairly sure it's sorted out at this point. My apologies for all the nonsense leading up to this point. |
Beautiful 💃 |
Once this is merged, I plan to continue teasing the internals of Ghost out into something that can be used as an express module. |
Am just testing it out ;) |
Aha fair enough :P |
I am super excited about this change, just took it for a spin and all is well. There is one concern, and that this is a very breaking change for anyone using Ghost as an npm module. I really don't want to have to hold this back for a major release or something lame like that - I want to hit the merge button right now! So, the question I wanted to throw out there is how best to message that this change will occur with 0.5.2? Ideally, I'd like the message to only appear to people using Ghost via I thought about echoing a warning from one of the Final idea was to put a message somewhere in the I can obviously also put a big warning on the releases page. Just wondering if anyone can think of a better way? @JoshWillik I'm not asking you to do this as part of this PR. My finger is hovering over the merge button and as soon as I'm sure we have an acceptable plan for how to message this I'll hit it! |
Update: Whoops sorry, I just did more testing and realised that |
|
||
function GhostServer(app) { | ||
this.app = app; | ||
this.httpListener = null; |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
I tested out changing these two lines and that fixes |
@ErisDS I'm not sure how this is a breaking change for those using NPM. If you If, however, a notification is required, it shouldn't be too hard to do something like this: function GhostServer(app) {
this.app = app;
this.httpListener = null;
this.upgradeTimeout = setTimeout( this.upgradeNotes.bind( this ), 10000 ) //HERE
}
GhostServer.prototype.start = function () {
// ...starting code
this.httpServer.on('listening', function () {
this.logStartMessages();
clearTimeout( this.upgradeTimeout ) //AND HERE
deferred.resolve(this);
}.bind(this));
return deferred.promise;
}
GhostServer.prototype.upgradeNotes = function(){
console.log( 'We have upgraded, notes notes' )
} This change adds very little complexity into the startup process, and is easy to remove when it's no longer needed. |
UpdateSorry, it seems I failed to look at the |
Aye that's why it's such a big deal ;) I don't want to change main to call the root I think the |
Okay cool. I'll batch this change in with the fixes to the |
|
||
// Restarts the ghost application | ||
GhostServer.prototype.restart = function () { | ||
this.stop().then(this.start); |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
Message something like:
|
So just to be clear the only change Instead of doing this:
They will now have to do this:
Right? |
@ErisDS 👍 |
So as far as middleware goes...that's not what express middleware currently looks like. Typically you get immediately returned a function that you can then attach to your express instance. I'm not sure we're able to synchronously return a function at this point in time, however we should in the future strive to return a function immediately that can then be mounted. Just some food for thought for the future. If we can reduce the amount of times we message to users how usage has changed the easier for everyone. |
Since the ghost internals rely so heavily on promises, I don't see an easy way to make the initial Despite this, mounting a ghost blog could still work:
It doesn't follow the normal express pattern perfectly, but I think it's workable enough for those of us who want a blog mounted in an express app. |
Update@hswolff on second thought, it might be possible to create another entry point that has a footprint like so:
I'm 95% confident that I can make a Does this sound good to you? It's more complex than the average express middleware, but it's certainly simpler than the code snippet I demo'd in the last comment. |
Whilst obviously, the end goal here is to achieve the ability to mount ghost as express middleware, and your suggestion sounds great, I don't think that detracts from the value of this PR? As in, we should get this patched and merged, and then we have a new API for controlling Ghost - the start and stopping of the server is isolated from the bootup code, and this will be useful for some advanced use cases (like people who want to add basic auth to the front of their blog). I think it will also make the code more easily testable. Then you can follow up with a second PR adding the middleware file which makes Ghost work as express middleware, which is like.. a whole other level of awesome? |
@ErisDS That sounds like a solid plan. |
👍 If it's done by ~2nd September, it'll all go out in an official release together, and ghost-as-npm-module users will be presented with the most excellent of choices. |
I see no reason I can't get this done by then. Update: Hah, promises? Because ghost uses... pr... forget it, bad joke |
closes TryGhost#3789 - Create a GhostServer class to manage state - index.js now calls start on the exported server - Alter tests to expect a GhostServer instance
2127e0a
to
1438278
Compare
It seems that the upgrade warning makes the Travis build logs really confusing. It still passes though. |
Confusing travis logs aren't the end of the world, we could disable this message when running in the testing environment, but it also acts as a reminder to remove the warning message at some point :) |
Good call :) — On Fri, Aug 22, 2014 at 2:39 PM, Hannah Wolfe notifications@github.com
|
Extract the starting functionality into an exported class.
closes #3789