Skip to content

Commit 0209f76

Browse files
danielmyhisak-jakobssonStiv-workDaniel Myhrman
authored andcommitted
Update web-server example to use Civetweb
Co-authored-by: Isak Jakobsson <[email protected]> Co-authored-by: Stiv Abdullwahed <[email protected]> Co-authored-by: Daniel Myhrman <[email protected]>
1 parent 3baddf0 commit 0209f76

File tree

9 files changed

+342
-371
lines changed

9 files changed

+342
-371
lines changed

web-server/.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
app/html*
21
app/lib*
3-
app/web_server_rev_proxy
2+
app/web_server_rev_proxy

web-server/Dockerfile

Lines changed: 9 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -13,70 +13,21 @@ ARG APP_RPATH=/usr/local/packages/web_server_rev_proxy
1313
ARG BUILD_DIR=/opt/build
1414

1515
#-------------------------------------------------------------------------------
16-
# Build Monkey library
16+
# Build Civetweb library
1717
#-------------------------------------------------------------------------------
18+
ARG CIVETWEB_BUILD_DIR=${BUILD_DIR}/civetweb
1819

19-
ARG MONKEY_VERSION=v1.5.6
20-
ARG MONKEY_GIT_REPO=https://github.com/monkey/monkey
21-
ARG MONKEY_DIR=${BUILD_DIR}/monkey
22-
ARG MONKEY_SRC_DIR=${MONKEY_DIR}/src
23-
ARG MONKEY_BUILD_DIR=${MONKEY_DIR}/build
24-
25-
WORKDIR ${MONKEY_DIR}
26-
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
27-
RUN git clone -b $MONKEY_VERSION $MONKEY_GIT_REPO ${MONKEY_SRC_DIR##*/}
28-
29-
# Remove unused directories
30-
WORKDIR ${MONKEY_SRC_DIR}
31-
RUN rm -rf \
32-
deps/jemalloc \
33-
debian* \
34-
src/contrib \
35-
examples
36-
37-
# Configure, build and install Monkey files
38-
COPY monkey.patch .
39-
RUN git apply --ignore-space-change --ignore-whitespace monkey.patch && \
40-
. /opt/axis/acapsdk/environment-setup* && \
41-
./configure \
42-
--enable-shared \
43-
--malloc-libc \
44-
--prefix=${SDK_LIB_PATH_BASE} \
45-
--libdir=${SDK_LIB_PATH_BASE}/lib \
46-
--bindir=${MONKEY_BUILD_DIR}/bin \
47-
--incdir=${MONKEY_BUILD_DIR}/include \
48-
--plugdir=${APP_RPATH}/lib/plugins \
49-
--datadir=${APP_RPATH}/html \
50-
--sysconfdir=${APP_RPATH}/html \
51-
--logdir=${APP_RPATH}/localhost/logs \
52-
--mandir=${MONKEY_BUILD_DIR}/man \
53-
--pidfile=/tmp/monkey.pid \
54-
--systemddir=/usr/lib/systemd/system && \
55-
make && \
56-
make install
57-
58-
# Gather files in Monkey build directory to make it easy for the application
59-
# Makefile to copy required files to the ACAP application build directory
60-
WORKDIR ${MONKEY_BUILD_DIR}/html
61-
ARG MONKEY_HTML_FILES="monkey.mime monkey.conf sites plugins.load"
62-
RUN for htmlfile in $MONKEY_HTML_FILES; do \
63-
cp -r "$APP_RPATH/html/$htmlfile" . ; \
64-
done
65-
66-
WORKDIR ${MONKEY_BUILD_DIR}/lib
67-
RUN cp -P ${SDK_LIB_PATH_BASE}/lib/libmonkey* .
68-
69-
WORKDIR ${MONKEY_BUILD_DIR}/lib/plugins
70-
ARG MONKEY_PLUGINS="monkey-liana"
71-
RUN for plug in $MONKEY_PLUGINS; do \
72-
cp "$APP_RPATH/lib/plugins/$plug.so" . ; \
73-
done
20+
WORKDIR ${BUILD_DIR}
21+
RUN git clone https://github.com/civetweb/civetweb.git
7422

23+
WORKDIR ${CIVETWEB_BUILD_DIR}
24+
RUN . /opt/axis/acapsdk/environment-setup* && make lib
25+
WORKDIR /opt/app
26+
RUN mkdir lib && cp ${CIVETWEB_BUILD_DIR}/libcivetweb.a lib
7527

7628
#-------------------------------------------------------------------------------
7729
# Build ACAP application
7830
#-------------------------------------------------------------------------------
7931

80-
WORKDIR /opt/app
8132
COPY ./app .
82-
RUN . /opt/axis/acapsdk/environment-setup* && acap-build .
33+
RUN . /opt/axis/acapsdk/environment-setup* && acap-build .

web-server/README.md

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
This example demonstrates how to setup the Axis device web server (Apache) in a
66
[Reverse Proxy](https://httpd.apache.org/docs/2.4/howto/reverse_proxy.html)
77
configuration, where HTTP requests to the application are routed to a web server
8-
[Monkey](https://github.com/monkey/monkey) running inside the ACAP application
8+
[CivetWeb](https://github.com/civetweb/civetweb) running inside the ACAP application
99
and acting as a CGI.
1010

1111
The advantage of a webserver proxy is that when porting existing code to your
@@ -17,7 +17,7 @@ a URL routing scheme as follows:
1717

1818
With `<appName>` and `<apiPath>` as defined in the manifest.
1919

20-
Note that this example shows the reverse proxy concept using Monkey, but you are
20+
Note that this example shows the reverse proxy concept using CivetWeb, but you are
2121
free to use any webserver of your choice.
2222

2323
## Alternative approach
@@ -36,7 +36,7 @@ route the requests to a web server running in the ACAP application.
3636

3737
The Apache server is configured using the `manifest.json` file in an ACAP
3838
application. In `manifest.json` under `configuration`, it is possible to specify
39-
a `settingPage` and a `reverseProxy` where the latter will connect the Monkey
39+
a `settingPage` and a `reverseProxy` where the latter will connect the CivetWeb
4040
server to the Apache server.
4141

4242
Prior to manifest 1.5.0, reverse proxy was only supported through the
@@ -51,21 +51,15 @@ configuration for the device. There are disadvantages with exposing Web
5151
Server directly to the network such as non standard ports and no reuse of
5252
authentication, TLS and other features that comes with Apache Server.
5353

54-
## Monkey web server
54+
## CivetWeb web server
5555

56-
Monkey is a fast and lightweight web server for Linux. It has been designed to
57-
be very scalable with low memory and CPU consumption, the perfect solution for
58-
Embedded Linux and high end production environments. Besides the common
59-
features as HTTP server, it expose a flexible C API which aims to behave as a
60-
fully HTTP development framework, so it can be extended as desired through the
61-
plugins interface. The Monkey Web Server
62-
[documentation](https://github.com/monkey/monkey-docs/) describes the
63-
configuration in detail.
64-
65-
> [!NOTE]
66-
> The main license of the Monkey repository is Apache, but some files
67-
> are licensed under other types such as GPL. Make sure to control how it
68-
> affects your application in order to be compliant.
56+
CivetWeb is an embeddable C web server for Linux. It is a great solution
57+
for running a web server on embedded Linux. Apart from being a
58+
HTTP server, it has a C API which can be extended as desired. The CivetWeb Web
59+
Server [documentation](https://github.com/civetweb/civetweb/) describes the
60+
configuration in detail. CivetWeb is open source, and will contain different
61+
licenses depending on the features you build it with. Please see
62+
[CivetWeb's repository](https://github.com/civetweb/civetweb/) for more information.
6963

7064
## Getting started
7165

@@ -75,13 +69,17 @@ structure used in the example:
7569
```sh
7670
web-server
7771
├── app
78-
│ ├── LICENSE - Text file which lists all open source licensed source code distributed with the application
79-
│ └── manifest.json - Defines the application and its configuration
80-
├── Dockerfile - Docker file with the specified Axis container image to build the example specified
81-
├── monkey.patch - Patch for using monkey examples in a native ACAP
82-
└── README.md - Step by step instructions on how to run the example
72+
│ ├── LICENSE
73+
│ └── manifest.json
74+
├── Dockerfile
75+
└── README.md
8376
```
8477

78+
- **app/LICENSE** - Lists open source licensed source code in the application.
79+
- **app/manifest.json** - Defines the application and its configuration.
80+
- **Dockerfile** - Builds an Axis container image and the specified example.
81+
- **README.md** - Step by step instructions on how to run the example.
82+
8583
## Limitations
8684

8785
- Apache Reverse Proxy can not translate content with absolute addresses (i.e.
@@ -102,7 +100,8 @@ Standing in your working directory run the following commands:
102100

103101
> [!NOTE]
104102
>
105-
> Depending on the network your local build machine is connected to, you may need to add proxy
103+
> Depending on the network your local build machine is connected to,
104+
you may need to add proxy
106105
> settings for Docker. See
107106
> [Proxy in build time](https://developer.axis.com/acap/develop/proxy/#proxy-in-build-time).
108107
@@ -148,9 +147,23 @@ http://<AXIS_DEVICE_IP>/index.html#apps
148147
A user can make a HTTP request to the application API using e.g. `curl`
149148

150149
```sh
151-
curl -u<USER>:<PASSWORD> --anyauth http://<AXIS_DEVICE_IP>/local/web_server_rev_proxy/my_web_server
152-
<html><body><h1>ACAP application with reverse proxy web server</h1><pre><br>Application name: web_server_rev_proxy<br>Reverse proxy path: /local/web_server_rev_proxy/my_web_server<br>Request timestamp: Fri Jan 24 14:54:47 2025
153-
</pre></body></html>
150+
curl -u <USER>:<PASSWORD> --anyauth http://<AXIS_DEVICE_IP>/local/web_server_rev_proxy/my_web_server
151+
```
152+
153+
Where the expected output is
154+
155+
```sh
156+
<html>
157+
<head><link rel="stylesheet" href="style.css"/></head>
158+
<title>
159+
ACAP Web Server Example
160+
</title>
161+
<body>
162+
<h1>ACAP Web Server Example</h1>
163+
Welcome to the web server example, this server is based on the
164+
<a href="https://github.com/civetweb/civetweb">CivetWeb</a> C library.
165+
</body>
166+
</html>
154167
```
155168

156169
As can be seen it's HTML code, browse to web page

0 commit comments

Comments
 (0)