Web server for Objective-C - html

How can I create a webserver from my Obj-C app, and post custom HTML to it?
Thanks!

Check:
SimpleHTTPServer
CocoaHTTPServer

To embed a lightweight HTTP server in iOS or Mac apps, check out GCDWebServer which has a modern and clean architecture designed on top of Grand Central Dispatch.

It would most likely be easier and far more secure to use something like FastCGI and then use an existing HTTP server such as Nginx to serve the HTML that your app passes along rather than trying to embed an HTTP server directly in your application. Plus Nginx is extremely fast and can handle huge server traffic without really breaking a sweat which not all other HTTP servers can say.
Plus using an embedded server means that your app and your HTTP server must run under the same UID which is bad from a security perspective as anyone compromising the HTTP server gains access to all your website files as well.

Related

Can I use html5 Websockets with windows domain authentication?

Our setup is like this: we use a coldfusion 10 server, and files are on a local intranet. Users use a domain login to access any files over https. I'm interested in using html5 websockets, but the first attempt gave me an error because no credentials were supplied. Is there a way around this? If not, is there a recommended technology for this scenario?
The user does log in on the client side. If it's possible, what I'd really like to do here is pass those credentials when making the connection to the server.
you should be able to supply the authentication header to your web socket server before the elevation to web socket read that and send it back in the headers for the elevation (first frame) then when the browser connects it should have the authentication it needs.
if your using a custom authentication E.G in page not authentication header you can also do this by passing any custom header to your server.
Or mandate that the first thing your web client sends is the authentication details this could be something like {username_hash}.{password_hash} if they don't close the socket to them.
Do not do this.
You're now responsible for sending and encrypting the authentication credentials yourself, bypassing something that already works and is tested.
Anyone can snoop on an unencrypted websocket port. Use HTTPs for an intranet, use stable solutions, don't reinvent this wheel because it tickles your fancy.
In a couple of years some colleague will have to maintain this and will have to figure out how your homebrew version works versus something that's solid like plain browser authentication.
My advice: Leave this to the browser and to well-tested coldfusion libraries.

Is it possible to send query to online database from an electron application?

I've been looking at solutions so that I can create a cross-platform fluid experience. So to do this for the online website version, I would just send an Ajax request to a PHP script to query a MySQL database. But I am thinking of creating an electron app for offline use, so I will need to send queries to that online database, but I know there are a lot of limitations when it comes to Ajax with regards to cross-site requests.
So is it possible to send these sort of ajax requests to a PHP script on a web server, from an electron application. But, if Ajax requests aren't possible, how would I achieve this type of request to an online database. I have tried doing some research on the subject but was unable to find any solutions that are similar to this situation.
Cross-domain AJAX requests are blocked by default. All your regular desktop apps such as your Mail client send requests out all the time. You simply have to enable Cross-Origin Resource Sharing (CORS) on your server. I don't know what server application you're using (Apache/Nginx), but for Apache you can start simply by adding the following line to the relevant part of your Virtual Host or .htaccess file:
Header set Access-Control-Allow-Origin "*"
You can refer to the Enable CORS to learn how to enable CORS for other server technologies.

Architecture for Intranet Application

I am planning to build a production application for a small & medium business. This is an intranet application with maximum 15 to 30 concurrent users. The proposed architecture is:
Client: Firefox browser
UI: HTML, JavaScript, CSS
Communication via: jQuery AJAX
Middle Tier: Window Service hosting WCF Service (using webHttpBinding)
Database: SQLServer 2012 Express Edition
In this architecture the missing part is a WebServer that will serve the static HTML pages. I do not want to go in with IIS mainly because of the following reasons:
Keep the cost of deployment down
Most of work is being done in the Window Service hosting WCF Service
Since most of the middle tier work is done by my Window Service hosting WCF Service and my UI is HTML, JavaScript & CSS, can we do away with the WebServer like IIS or other WebServers supporting ASP.NET technology and use a lightweight WebServers which serves only static HTML pages something like lighttpd, nginx etc?
Are these light weight WebServers like lighttpd, nginx suitable to host in production environment.
There might be an issue of AJAX Cross Domain requests as Window Service hosting WCF Service and the lightweight WebServer may run on different port but on the same IP address. We can probably overcome this by opening it up to cross domain requests as it’s an intranet application.
One of the ideas behind this architecture is that I want to try and reuse this in other projects which are bigger in size.
Please let me know if this is possible and the related pros & cons of this approach. I am also open to any other suggestions which will help me improve this architecture.
I think you're overdesigning it for such a small site. If you're anyway going to run a WCF service it shouldn't be a problem to use IIS.
I'd suggest to either use ASP.NET MVC and do the html rendering on the server, or to go for a client side library such as angular.js in combination with Web API.

How to downgrade from websocket to http?

I've been reading abit about html5, websockets and http. I made some simple tests but let's say I want to do this:
Browser makes an http connection to a web server
Browser then negotiates a web socket connection to the same web server
At some point browser wants to talk http again with the web server in the same session
Points 1 and 2 are straightforward. Coming to point 3, is there a standard solution available? I'm guessing that closing a web socket by either side terminates the existing connection right? Can there be a way to perform a "downgrade" from websockets back to http?
I guess what I'm looking for is a standards-based solution but if one doesnt exist, do any frameworks exist that can do the job?
Thanks :o)
Nina

Using SSI (Server Side Includes)

I'm trying to learn how to do Server Side Includes because I need them for a project of mine. Now, can I use SSI locally? My site is 100% HTML, Javascript, and CSS, so there is no server running my stuff. I'm just editing the files in notepad. What can I do to allow me to work on SSI before I upload it to the server that I plan on sending it to.
What can I do to allow me to work on SSI before I upload it to the server...?
If you're not running a server, then you can't use server-side includes. The clue is in the name. So if you're testing the page locally without a server, then your SSIs won't work.
The only way you're going to be able to do this is to install a web server on your local PC.
Fortunately this is fairly easy. The two major web servers are Apache and IIS. Apache is free; you can download it and install it for free. IIS is a commercial product (by Microsoft), but there is a cut-down version you can install for free. Pick whichever one is best for you (ie the one which matches your actual web server), and you should be able to get your SSI code working. You'll probably need to do some config to set it up, but as a web developer that's a good thing to know how to do.
You need to run a server locally to make ssi work. You can install just apache, or use XAMPP (lite) to also get PHP and MySQL.
Server Side Includes (SSI) are an optional feature of the web servers helping the developers to include HTML file content from a base file into multiple other HTML files with a single line of code. We need this if we are creating a simple, elegant and fast pure HTML site, without active server computing, just invoking content delivery capabilities of the server.
There are 3 major steps required to get SSI running on IIS 7 and later:
Configure IIS roles,
Extend IIS handlers,
Invoke a SSI call in you HTML code.
HERE is a more detailed explanation.