mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-28 23:49:44 +08:00
Add Embedded Filesystem example
This commit is contained in:
parent
79c49e64e8
commit
014a008c3a
51
examples/embedded-filesystem/Makefile
Normal file
51
examples/embedded-filesystem/Makefile
Normal file
@ -0,0 +1,51 @@
|
||||
PROG ?= example
|
||||
SOURCES ?= ../../mongoose.c main.c packed_fs.c
|
||||
CFLAGS ?= -I../.. -DMG_ENABLE_PACKED_FS=1 -DMG_ENABLE_LINES=1 $(EXTRA)
|
||||
FILES_TO_EMBED ?= $(wildcard web_root/*)
|
||||
ROOT ?= $(realpath $(CURDIR)/../../..)
|
||||
DOCKER ?= docker run --rm -e Tmp=. -e WINEDEBUG=-all -v $(ROOT):$(ROOT) -w $(CURDIR)
|
||||
VC98 ?= $(DOCKER) mdashnet/vc98 wine
|
||||
MINGW ?= $(DOCKER) mdashnet/mingw
|
||||
|
||||
all: $(PROG)
|
||||
$(RUN) ./$(PROG)
|
||||
|
||||
$(PROG): $(SOURCES) $(FILES_TO_EMBED)
|
||||
$(CC) ../../test/pack.c -o pack
|
||||
./pack $(FILES_TO_EMBED) > packed_fs.c
|
||||
$(CC) -W -Wall -Wextra -O0 -g3 $(CFLAGS) -o $(PROG) $(SOURCES)
|
||||
|
||||
|
||||
mingw: $(SOURCES) $(FILES_TO_EMBED)
|
||||
$(MINGW) i686-w64-mingw32-gcc $(CFLAGS) ../../test/pack.c -o pack.exe
|
||||
$(MINGW) wine cmd /c 'pack.exe $(FILES_TO_EMBED) > packed_fs.c'
|
||||
$(MINGW) i686-w64-mingw32-gcc $(CFLAGS) $(SOURCES) -lws2_32 -o $(PROG).exe
|
||||
$(MINGW) wine $(PROG).exe
|
||||
|
||||
vc98: $(SOURCES) $(FILES_TO_EMBED)
|
||||
$(VC98) cl.exe /nologo $(CFLAGS) ../../test/pack.c /Fepack.exe
|
||||
$(VC98) cmd /c 'pack.exe $(FILES_TO_EMBED) > packed_fs.c'
|
||||
$(VC98) cl.exe /nologo /O2 $(CFLAGS) $(SOURCES) /Fe$(PROG).exe
|
||||
$(VC98) $(PROG).exe
|
||||
|
||||
clean:
|
||||
rm -rf $(PROG) *.o *.dSYM *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb log.txt pack
|
||||
|
||||
.PHONY: compress expand gzipped plain all
|
||||
|
||||
gzipped: compress
|
||||
$(MAKE) all
|
||||
|
||||
plain: expand
|
||||
$(MAKE) all
|
||||
|
||||
compress:
|
||||
for file in $(FILES_TO_EMBED) ; do \
|
||||
gzip -q $$file ; \
|
||||
done
|
||||
|
||||
expand:
|
||||
for file in $(FILES_TO_EMBED) ; do \
|
||||
gunzip -q $$file ; \
|
||||
done
|
||||
|
28
examples/embedded-filesystem/main.c
Normal file
28
examples/embedded-filesystem/main.c
Normal file
@ -0,0 +1,28 @@
|
||||
// Copyright (c) 2022 Cesanta Software Limited
|
||||
// All rights reserved
|
||||
|
||||
#include "mongoose.h"
|
||||
|
||||
const char *s_listening_url = "http://0.0.0.0:8000";
|
||||
|
||||
// HTTP request handler function
|
||||
void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
||||
if (ev == MG_EV_HTTP_MSG) {
|
||||
struct mg_http_serve_opts opts = {
|
||||
.root_dir = "/web_root",
|
||||
.fs = &mg_fs_packed
|
||||
};
|
||||
mg_http_serve_dir(c, ev_data, &opts);
|
||||
}
|
||||
(void) fn_data;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
struct mg_mgr mgr;
|
||||
mg_log_set(MG_LL_INFO);
|
||||
mg_mgr_init(&mgr);
|
||||
mg_http_listen(&mgr, s_listening_url, fn, NULL);
|
||||
while (true) mg_mgr_poll(&mgr, 500);
|
||||
mg_mgr_free(&mgr);
|
||||
return 0;
|
||||
}
|
1565
examples/embedded-filesystem/packed_fs.c
Normal file
1565
examples/embedded-filesystem/packed_fs.c
Normal file
File diff suppressed because it is too large
Load Diff
13
examples/embedded-filesystem/web_root/index.html
Normal file
13
examples/embedded-filesystem/web_root/index.html
Normal file
@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta name="description" content="Mongoose Embedded Filesytem example" />
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Mongoose Embedded Filesytem example</title>
|
||||
<link rel="stylesheet" href="style.css" />
|
||||
</head>
|
||||
<body></body>
|
||||
<script type="module" src="main.js"></script>
|
||||
</html>
|
88
examples/embedded-filesystem/web_root/main.js
Normal file
88
examples/embedded-filesystem/web_root/main.js
Normal file
@ -0,0 +1,88 @@
|
||||
'use strict';
|
||||
import { h, html, render } from './preact.min.js';
|
||||
|
||||
|
||||
const X = function () {
|
||||
|
||||
return html`
|
||||
<div class="container">
|
||||
<h2 class="section">ABOUT US</h2>
|
||||
<div class="row">
|
||||
<div class="col-7">
|
||||
<p>
|
||||
Cesanta Software Ltd. is headquartered in Dublin, Republic of Ireland.
|
||||
</p>
|
||||
<p></p>
|
||||
Our story roots back to 2004, when Mongoose Web Server Library development started. <br>
|
||||
|
||||
As Mongoose Web Server grew in popularity and matured over the following years, in 2013 Cesanta was established to continue its development and
|
||||
provide support to our valued customers.
|
||||
</p>
|
||||
<p>We are proud to have among our customers many <i>Fortune 500</i> companies as well as medium and small size businesses.
|
||||
Security and quality of our solutions is a paramount for us and the fact that Mongoose Web Server is used by NASA aboard the International Space Station is
|
||||
the best confirmation to it.</p>
|
||||
<p>Since 2013, Cesanta has expanded its product portfolio. We develop and distribute embedded software and hardware with focus on connected products and the Internet of Things.</p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
};
|
||||
|
||||
const Y = function () {
|
||||
|
||||
return html`
|
||||
<div class="container">
|
||||
<h3 class="section">Among our products are:</h3>
|
||||
<div class="row">
|
||||
<div class="col-7">
|
||||
<ul>
|
||||
<li>
|
||||
<a href="https://mongoose.ws/">Mongoose Web Server</a>
|
||||
- an embedded web server and networking library
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://vcon.io/">VCON.io</a>
|
||||
- Arduino-compatible boards with built-in firmware OTA updates
|
||||
and management dashboard
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://mdash.net/">mDash.net</a>
|
||||
- an all-in-one IoT Platform
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://mongoose-os.com">Mongoose OS</a>
|
||||
- an operating system for low-power microcontrollers
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="https://github.com/cesanta/mjs">mJS</a>
|
||||
- an embedded JavaScript engine for C/C++
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<p><b>Our solutions are:</b></p>
|
||||
<ul>
|
||||
<li>integrated into thousands of commercial products</li>
|
||||
<li>deployed to hundreds of millions devices in production environments</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
};
|
||||
|
||||
const App = function (props) {
|
||||
|
||||
return html`
|
||||
<h1>Basic Embedded Filesystem demo</h1>
|
||||
<div>
|
||||
${h(X)}
|
||||
</div>
|
||||
<div>
|
||||
${h(Y)}
|
||||
</div>`;
|
||||
};
|
||||
|
||||
window.onload = () => render(h(App), document.body);
|
1
examples/embedded-filesystem/web_root/preact.min.js
vendored
Normal file
1
examples/embedded-filesystem/web_root/preact.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
43
examples/embedded-filesystem/web_root/style.css
Normal file
43
examples/embedded-filesystem/web_root/style.css
Normal file
@ -0,0 +1,43 @@
|
||||
* { box-sizing: border-box; }
|
||||
html, body { margin: 0; padding: 0; height: 100%; font: 16px sans-serif; }
|
||||
select, input, label::before, textarea { outline: none; box-shadow:none !important; border: 1px solid #ccc !important; }
|
||||
code, pre { color: #373; font-family: monospace; font-weight: bolder; font-size: smaller; background: #ddd; padding: 0.1em 0.3em; border-radius: 0.2em; }
|
||||
textarea, input, .addon { font-size: 15px; border: 1px solid #ccc; padding: 0.5em; }
|
||||
a, a:visited, a:active { color: #55f; }
|
||||
.addon { background: #eee; min-width: 9em;}
|
||||
.btn {
|
||||
background: #ccc; border-radius: 0.3em; border: 0; color: #fff; cursor: pointer;
|
||||
display: inline-block; padding: 0.6em 2em; font-weight: bolder;
|
||||
}
|
||||
.btn[disabled] { opacity: 0.5; cursor: auto;}
|
||||
.smooth { transition: all .2s; }
|
||||
.container { margin: 0 20px; width: auto; }
|
||||
.d-flex { display: flex; }
|
||||
.d-none { display: none; }
|
||||
.border { border: 1px solid #ddd; }
|
||||
.rounded { border-radius: 0.5em; }
|
||||
.nowrap { white-space: nowrap; }
|
||||
.msg { background: #def; border-left: 5px solid #59d; padding: 0.5em; font-size: 90%; margin: 1em 0; }
|
||||
.section { margin: 0 1em; }
|
||||
.topic, .data, .qos { padding: 0.2em 0.5em; border-radius: 0.4em; margin-right: 0.5em; }
|
||||
.qos { background: #efa; }
|
||||
.topic { background: #fea; }
|
||||
.data { background: #aef; }
|
||||
|
||||
/* Grid */
|
||||
.row { display: flex; flex-wrap: wrap; }
|
||||
.col { margin: 0; padding: 0; overflow: auto; }
|
||||
.col-12 { width: 100%; }
|
||||
.col-11 { width: 91.66%; }
|
||||
.col-10 { width: 83.33%; }
|
||||
.col-9 { width: 75%; }
|
||||
.col-8 { width: 66.66%; }
|
||||
.col-7 { width: 58.33%; }
|
||||
.col-6 { width: 50%; }
|
||||
.col-5 { width: 41.66%; }
|
||||
.col-4 { width: 33.33%; }
|
||||
.col-3 { width: 25%; }
|
||||
.col-2 { width: 16.66%; }
|
||||
.col-1 { width: 8.33%; }
|
||||
@media (min-width: 1310px) { .container { margin: auto; width: 1270px; } }
|
||||
@media (max-width: 920px) { .row .col { width: 100%; } }
|
Loading…
x
Reference in New Issue
Block a user