MCPcopy Create free account
hub / github.com/SmingHub/Sming / startWebServer

Function startWebServer

samples/HttpServer_Plugins/app/application.cpp:28–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26}
27
28void startWebServer()
29{
30 server = new HttpServer;
31
32 server->listen(80);
33 server->paths.set("/", echoContentBody);
34 server->paths.setDefault(echoContentBody);
35
36 /*
37 * By default the server does not store the incoming information.
38 * There has to be either a plugin that does this or a body parser.
39 * In this sample we use a body parser that stores the information into memory.
40 */
41 server->setBodyParser(MIME_FORM_URL_ENCODED, bodyToStringParser);
42
43 // Here we use a simple plugin that protects the access to a resource using HTTP Basic Authentication
44 auto pluginBasicAuth = new ResourceBasicAuth("realm", "username", "password");
45 // You can add one or more authentication methods or other plugins...
46 server->paths.set("/auth", echoContentBody, pluginBasicAuth);
47
48 /*
49 * The plugins will be registered in the order in which they are provided.
50 * For example in the command below the IP restriction plugin will be registered first
51 * followed by the basic authentication plugin.
52 * You can run the following curl command to test these plugins:
53 *
54 * curl -vvv http://username:password@192.168.13.10/ip-n-auth
55 *
56 * make sure to replace the IP address with the IP address of your HttpServer
57 */
58 server->paths.set("/ip-n-auth", echoContentBody, new ResourceIpAuth(F("192.168.13.0"), F("255.255.255.0")),
59 pluginBasicAuth);
60
61 /*
62 * This content coming to this resource is modified on the fly
63 * using our ContentDecoder plugin. See the source code of ContentDecoder
64 * to get an idea how to create your own plugin.
65 * You can run the following curl command to test this plugin:
66 *
67 * curl -vvv http://username@192.168.13.10/test -d "1234" -H "Content-Encoding: test"
68 *
69 * make sure to replace the IP address with the IP address of your HttpServer
70 */
71 server->paths.set("/test", echoContentBody, new ContentDecoder());
72
73 Serial << endl
74 << _F("=== WEB SERVER STARTED ===") << endl
75 << WifiStation.getIP() << endl
76 << _F("==============================") << endl
77 << endl;
78}
79
80// Will be called when WiFi station becomes fully operational
81void gotIP(IpAddress ip, IpAddress netmask, IpAddress gateway)

Callers 1

gotIPFunction · 0.70

Calls 6

setDefaultMethod · 0.80
setBodyParserMethod · 0.80
FFunction · 0.50
listenMethod · 0.45
setMethod · 0.45
getIPMethod · 0.45

Tested by

no test coverage detected