Skip to main content

Running webservers

Some type of applications contain their own webserver, which is responsible for serving HTTP requests. This guide will show you how to create a webserver application and make it accessible via HTTP. Examples for these kinds of applications are:

Prerequisites

As a prerequisite, you need an mStudio application that contains a webserver, for example a Node.js or Python application. The application needs to have an "entrypoint"; meaning a console command that starts your webserver. The entrypoint command must fulfill the following requirements:

  • It should open a local TCP port on which the webserver listens for incoming HTTP requests; the port is provided via the PORT environment variable.
  • The command should run the webserver in the foreground, so that the process does not exit immediately.

Making your app accessible via HTTP

After you have created your webserver application, you can make it accessible via HTTP. Our platform will make sure that the process that you have configured as "entrypoint" in the previous step will be running at all times.

You can connect your application to the internet by linking it to a domain via the mStudio or the API. Our platform will take care of routing any traffic to that domain to your application, and will also handle TLS termination, if you have configured a certificate.

Your application simply needs to listen for plain HTTP traffic on a port that should be read from the PORT environment variable.

Managing your process lifecycle

With a webserver application, the entire lifecycle of your process is managed within the application itself. Within your hosting environment, your process is managed by the mittnite init system, a lightweight process manager that is responsible for starting, stopping and restarting your application.

Within your hosting environment, you can use the mittnitectl command to manage your application:

  • mittnitectl job start starts your application
  • mittnitectl job stop stops your application
  • mittnitectl job restart restarts your application

You can also use mittnitectl to view the status of your application:

  • mittnitectl job status shows the status of your application
  • mittnitectl job logs shows the logs of your application