Skip to content

Latest commit

 

History

History
39 lines (24 loc) · 2.15 KB

File metadata and controls

39 lines (24 loc) · 2.15 KB
id running-webserver
title Run a web server
description Run an HTTP server inside your Actor for monitoring or serving content during execution.

import RunnableCodeBlock from '@site/src/components/RunnableCodeBlock';

import WebserverExample from '!!raw-loader!roa-loader!./code/07_webserver.py';

In this guide, you'll learn how to run a web server inside your Apify Actor. This is useful for monitoring Actor progress, creating custom APIs, or serving content during the Actor run.

Introduction

Each Actor run on the Apify platform is assigned a unique hard-to-guess URL (for example https://8segt5i81sokzm.runs.apify.net), which enables HTTP access to an optional web server running inside the Actor run's container.

The URL is available in the following places:

  • In Apify Console, on the Actor run details page as the Container URL field.
  • In the API as the container_url property of the Run object.
  • In the Actor as the Actor.configuration.container_url property.

The web server running inside the container must listen at the port defined by the Actor.configuration.container_port property. When running Actors locally, the port defaults to 4321, so the web server will be accessible at http://localhost:4321.

Example Actor

The following example shows how to start a simple web server in your Actor, which will respond to every GET request with the number of items that the Actor has processed so far:

{WebserverExample}

Conclusion

In this guide, you learned how to run a web server inside your Apify Actor. By leveraging the container URL and port provided by the platform, you can expose HTTP endpoints for monitoring, reporting, or serving content during Actor execution. If you have questions or need assistance, feel free to reach out on our GitHub or join our Discord community.

Additional resources