Serving web pages

Hi,

I have an idea for a project to solve a complex problem I have. I want to write an app in Xojo that will run in the menubar on OS X (easily achievable). That app will manage a library of medical images that I add to it (achievable, I have written code in Xojo to parse medical images). What I want to be able to do is view these images in a web browser.

I need some sort of bridge where I can write the frontend in HTML / PHP (which I’m comfortable with) but the PHP app will need to talk to the Xojo app in order to be served up the managed images.

I don’t want to use the Web framework for Xojo as I just don’t like it.

Is this possible? Any idea how to approach this or am I making things way too complicated? The issue arises from the fact that javascript doesn’t have an easy way to quickly pull images from a hard drive on a user’s computer (hence the need for the Xojo bridge). Also, I’d prefer a Xojo app to organise my images as I think that would be easier to implement than a web-based management system.

For those that use Plex (not affiliated but amazing), this is kind of what that app does for video and music. I.e there is “server app” running constantly on your Mac which is accessible from a URL.

[quote=184389:@Garry Pettet]Hi,

I have an idea for a project to solve a complex problem I have. I want to write an app in Xojo that will run in the menubar on OS X (easily achievable). That app will manage a library of medical images that I add to it (achievable, I have written code in Xojo to parse medical images). What I want to be able to do is view these images in a web browser.

I need some sort of bridge where I can write the frontend in HTML / PHP (which I’m comfortable with) but the PHP app will need to talk to the Xojo app in order to be served up the managed images.

I don’t want to use the Web framework for Xojo as I just don’t like it.

Is this possible? Any idea how to approach this or am I making things way too complicated? The issue arises from the fact that javascript doesn’t have an easy way to quickly pull images from a hard drive on a user’s computer (hence the need for the Xojo bridge). Also, I’d prefer a Xojo app to organise my images as I think that would be easier to implement than a web-based management system.

For those that use Plex (not affiliated but amazing), this is kind of what that app does for video and music. I.e there is “server app” running constantly on your Mac which is accessible from a URL.[/quote]

So in essence you want to have a WebServer on your machine but not use Web Edition to do it ?

In Desktop you have ServerSocket so you can easily serve HTML pages from an app, and with a minimal amount of work pull images and database stuff then add that to HTML. See the ServerSocket example in the communication examples.

Php is installed on the Mac, but I do not see how you could serve that through ServerSocket. The best way would rather be to have php pages served by Apache.

At first glance, you could have an HTML/Php site served by Apache on localhost, and when needed, links to your desktop server, as you would with a standalone web app as localhost:8080 or other port, with the proper parameter to have the desired image served.

I know you said you don’t want to use web edition, but maybe you could use it for the back end only?

if you only use app.handleURL and/or app.handleSpecialURL and ignore the rest, you could use php to call the Xojo webapp (like an API/SOAP service) and return the content from that back to your php page?

just a thought.

These are useful suggestions.

In essence, I’d much prefer doing the frontend development in HTML/PHP/javascript as I think the end effect will be nicer and more flexible but I need to do quite a bit of backend transcoding/image manipulation, etc which I’m not confident I can do with PHP (but know I can do with Xojo). I hadn’t thought of using Web Edition as you had suggested @Russ Lunn. To follow up on your point @Michel Bujardet, do you think ServerSocket could respond to an API call from my PHP app to serve up images it has access to locally? Just trying to avoid Web Edition as I only have a desktop license (plus I really want a Mac menubar interface).

[quote=184434:@Garry Pettet]These are useful suggestions.

In essence, I’d much prefer doing the frontend development in HTML/PHP/javascript as I think the end effect will be nicer and more flexible but I need to do quite a bit of backend transcoding/image manipulation, etc which I’m not confident I can do with PHP (but know I can do with Xojo). I hadn’t thought of using Web Edition as you had suggested @Russ Lunn. To follow up on your point @Michel Bujardet, do you think ServerSocket could respond to an API call from my PHP app to serve up images it has access to locally? Just trying to avoid Web Edition as I only have a desktop license (plus I really want a Mac menubar interface).[/quote]

At the risk of shocking some, and although I am very fond of WE, none of my sites presents a WE front end. I rather use HTML/Php/JavaScript as front end, and be assured my site will always respond, than to have a web site that goes “database not found” on visitors, as I have seen this week end on another developer site.

To me, WE is splendid, but like using a Ferrari to go to the market everyday. It is bound to break.

Sorry Garry, I was digressing.

Look at the example of serverSocket. Run it, click Listen, and connect a browser to http://localhost:11234/. You will see this in the app window. Now add a parameter to the URL, such as http://localhost:11234/?roadrunner and you will see that as a get request. While on your browser screen you will see the response “From the server socket, I connected to you”. In essence, that already constitutes a crude API. I would take very little work to have it serve pictures with your own protocol.

I imagine you could have an HTML or PHP pages with links to localhost:11234 and parameters for what you want served. That is a very simple design which should prove very robust.

@Russ Lunn : the serverSocket desktop example does very much what handleURL could do. Unless I am mistaken, WE standalone is based on a similar socket.

@Michel Bujardet I think you are correct about Web Edition essentially being a wrapper for the server socket.

I have had lots of success with WE in general, however I’m not pretending it’s the prettiest or most responsive! I find it’s certainly good enough for anything I need. On the database front, I find most issues I have are with the native xojo stuff, so I use mbssql now.

Anyway, I was just pointing out that WE can be used as a way to provide an API /service without needing all the layout stuff and it’s all pretty much done for you. If your competent enough to roll it yourself then that’s possibly the way to go. Although I’ve written servers on c and .net and I’m moving it all to WE now, except for the really time critical stuff.

[quote=184448:@Russ Lunn]@Michel Bujardet I think you are correct about Web Edition essentially being a wrapper for the server socket.

I have had lots of success with WE in general, however I’m not pretending it’s the prettiest or most responsive! I find it’s certainly good enough for anything I need. On the database front, I find most issues I have are with the native xojo stuff, so I use mbssql now.

Anyway, I was just pointing out that WE can be used as a way to provide an API /service without needing all the layout stuff and it’s all pretty much done for you. If your competent enough to roll it yourself then that’s possibly the way to go. Although I’ve written servers on c and .net and I’m moving it all to WE now, except for the really time critical stuff.[/quote]

I am not suggesting in any way to use C or any weird thing. It just happens so the desktop ServerSocket does pretty much what WE HandleURL does. And as much as I like WE, it has so much slower than desktop, even if it were not for Garry’s need for a menubar, I think desktop will probably perform better for serving local files.

I’ve used https://thezaz.com/code/httpserver/ with good results when I needed to create document rendering server for another system.

I’m playing around with the ServerSocket example. Visiting http://localhost:11234/ in my browser when the demo app is running shows me this in the app:

but I never see the “From the server socket, I connected to you” message in the browser. In fact, the browser just shows a never ending loading bar in the URL bar with no content in the browser…

@Bob Coleman The current version of Thom’s HTTPServer class (on Github) seems to work out of the box but won’t send local CSS files. If I have a simple HTML with or without a CSS link to an externally hosted CSS file, it works OK. If I try to include a CSS file that is being hosted by the HTTPServer then it doesn’t return the CSS file to the browser…

Indeed the message is displayed fine in Chrome, but not in Safari.

I mainly used it to act as RPC server. But didn’t have a problem with serving up static content. Did you add a handler for the css directory?

Yep. Seeing that behaviour too - shows the message on Chrome but not Safari or Firefox.

@Bob Coleman Hmm, nope. I may have to read the docs more closely (they are very sparse in the new project). I just added a stylesheet link to a .css file in the ServerRoot directory (the same directory that had the HTML file that was being served up correctly) and it doesn’t serve up the CSS file specified. If you host the same CSS file remotely and put a stylesheet link to it from the index page then the CSS is loaded.

Any idea how to add CSS handling to the HTTP Server? It’s not particularly clear…

Just so I was comparing apples to apples I downloaded the latest version then put the following as the page:

[code]

Test Page

This is a test.

[/code] And the css did not load. Then I changed the link tag to: [code][/code] and it worked.

So are these images local or do they need to be pulled from a remote DB/server?

If they are local, why not just use a file:/// style URL? Then you can just pull the image straight off the disk.

[quote=184508:@Bob Coleman]Just so I was comparing apples to apples I downloaded the latest version then put the following as the page:

[code]

Test Page

This is a test.

[/code] And the css did not load. Then I changed the link tag to: [code][/code] and it worked.[/quote]

You’re right. Got it working. Thanks!