Click here to Skip to main content
15,881,380 members
Articles / Hosted Services / Web Hosting

HostMe - Hosting Static Web Pages Has Never Been Easier

Rate me:
Please Sign up or sign in to vote.
4.09/5 (8 votes)
18 Jun 2017MIT4 min read 25.5K   716   18   4
HostMe is a simple one EXE application that can host your static web pages easily. It can run either as a console or as a Windows service with the minimal amount of effort from your side.

Source on GitHub

Introduction

Not every time you host a web site you need a server side logic. When all you need is just static web pages hosting using something that just hosts your site, and does nothing else, can do the work for you.

Background

Many web sites today are written as single page applications. Usually, those sites don't need a traditional server side, the client performs some http requests to some services, maybe even microservices, just to get the relevant data. The rest of the work is performed in the browser. In such a case, hosting static web pages is enough.

In this article, I want to introduce an application that I wrote (HostMe) that does exactly this.

All you need to do to host static pages with HostMe is just to run a single EXE file (no any kind of installation is required).

Using HostMe

  1. Download HostMe.
  2. Put HostMe.exe in the same directory where your index.html file is found:

    Image 1

  3. Run HostMe.exe as administrator (The default hosting port is on port 80, in order to host on port 80, you need to run as administrator. If you would like to change the default port, look here):

    Image 2

  4. Now you can open your browser and type localhost:

    Image 3

You can see that all site files were loaded perfectly, even the javascript code. If you want to try it by yourself, you can download this example.

Pay attention that you don't need to restart HostMe at any point, any addition of new file or change to existing file will be effected immediately.

Run HostMe as a Windows Service

Run the cmd as administrator (in order to install Windows service, you must be administrator), go to the folder where HostMe.exe is found and type:

HostMe.exe -install

Image 4

Now you have a Windows service running that will host your site and start automatically on every system boot. You can see it in the services.msc:

Image 5

You can enter localhost again in the browser, and it works like a charm:

Image 6

If you want to uninstall the service, all you need to do is this:

C#
HostMe.exe -uninstall

You even don't need to stop the Windows service first.

Logs

HostMe writes to log files every request it gets. You can see it in the logs folder that will be created in the same directory as the EXE.

Please pay attention that since the logs folder is found in the same directory as HostMe.exe and you use the default configuration, any user can access your logs files. If you don't want this to be possible, change the root directory in the site as explained in the next section.

Change the Default Configuration

The default configuration of HostMe is to run on port 80 and to host what is found in the same directory where the EXE is found.

In order to change this behavior, create a new json file called HostMe.config.json in the same directory as the EXE. The file's content should be in this format:

C#
{
  "Path": "C:\MySite\siteRoot",
  "Port": 8080
}

The path is the path to the root folder of the site. It can be either relative to the EXE or absolute.

The port is the port on which the site will be hosted.

If you omit one of the properties, it will get its default value (the port will be 80 and the root folder will be the folder of the EXE).

So, if you just want to change the root folder of the site to siteRoot, and your EXE is found in C:\MySite, you can write this:

C#
{
   "Path": "C:\MySite\siteRoot"
}

or that:

C#
{ 
    "Path": "siteRoot" 
}

What's Next?

The code of HostMe is actually an open source and can be found here.

If you want some explanations about the code, I will be glad to write another article with explanations.

Feel free to write any suggestions or issues you have found.

Useful Links

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionMy vote of 5 Pin
Qwertie12-Apr-16 15:11
Qwertie12-Apr-16 15:11 
Questionmono Pin
keeny_cp212-Apr-16 6:46
keeny_cp212-Apr-16 6:46 
AnswerRe: mono Pin
Alon Lek12-Apr-16 8:07
Alon Lek12-Apr-16 8:07 
GeneralRe: mono Pin
Qwertie12-Apr-16 15:06
Qwertie12-Apr-16 15:06 
Why not? Does it use an API that Mono doesn't have? If you stick to basic BCL features, it should Just Work under Mono.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.