Finding the current preview URL using RWPluginKit

Hey everyone,

I’m trying to extract the current web server URL (used in preview) and didn’t see anything that stood out to me in the SDK headers. I noticed in the private headers there are a few options for configuring the behavior, but nothing which exposes the current port or server status. Plus, I suspect that using private headers is a bad idea.

Is there something I may have missed?

I’ve come up with a clever way to derive the current URL myself, but I fear it may not work correctly in future releases if the server changes in a significant way.

CC: @tpbradley

Hey @mikey,

I’m afraid there isn’t a way to obtain the preview web server’s URL directly but you can extract it from the “path” property in the export parameters passed to the plugin’s - (id)contentHTML: method during export.

Is this how you’ve been able to derive the URL?


Hey @tpbradley,

I was able to derive the preview server’s URL by inspecting the child processes of NSRunningApplication (RW), filtering them by their working directory (i.e. sibling of the plugin’s temporary directory), and finally inspecting its open port.

I’ll take a look at the export parameters and see if that works… it certainly would be less fragile, considering the preview server topology is subject to change :slight_smile:


@tpbradley Come to think of it, assuming I’m able to extract it from the export, wouldn’t that mean the user would have to explicitly trigger an export before the plugin could be used? Or would that happen automatically if a page was created with the preview server active?

Oh I see, that’s some great thinking outside the box! I don’t see the preview server changing in the near future so it should work for some time.

Yes the user would have to trigger an export or preview of your page. I don’t think this is going to do what you want. It’s the Emporter app you’re working on isn’t it? Allowing a remote user to preview content from RW’s web server?

A proper API call to grab the server URL would be far better.

I have to apologise, the export params doesn’t contain the server URL, it contains the path to the preview folder on disk. My mind is deep in AWS code right now lol

@tpbradley Yikes! I totally understand… the AWS console alone is not for the faint of heart :joy:

Yes, the plugin is for the Emporter app, so I hadn’t planned on having anything to export.

Glad to hear that the preview server is stable for the time being. I’ll keep the current code as-is until the preview URL is exposed properly. For what it’s worth, I plan on the plugin being open source, so if there’s any potential breakage it’ll be possible to have multiple eyes on it.


1 Like

Sounds great man! Can’t wait have a play :wink: