diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 913b51d..a201148 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -8,4 +8,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v1
- name: Build
- run: docker run -v ${PWD}:/opt/esp32-javascript -w /opt/esp32-javascript -t espressif/idf idf.py build
+ run: |
+ docker build -t esp32-javascript:latest -f tools/Dockerfile .
+ docker run -t esp32-javascript:latest bash -c '. ./tools/install-node.sh; idf.py build'
diff --git a/.gitignore b/.gitignore
index 7e5baba..4301c8c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
build
sdkconfig.old*
-main/project.cpp
\ No newline at end of file
+main/project.cpp
+node_modules
+
diff --git a/.npmrc b/.npmrc
new file mode 100644
index 0000000..43c97e7
--- /dev/null
+++ b/.npmrc
@@ -0,0 +1 @@
+package-lock=false
diff --git a/README.md b/README.md
index 7b92977..c5d1237 100644
--- a/README.md
+++ b/README.md
@@ -91,7 +91,7 @@ You can clean the project with
Tested with esp-idf (master branch commit hash 2e14149b).
## API
-[API documentation](api.md)
+[API documentation](docs/README.md)
## License
See source files.
diff --git a/api.md b/api.md
deleted file mode 100644
index 1a41bc6..0000000
--- a/api.md
+++ /dev/null
@@ -1,192 +0,0 @@
-# API
-
-This documentation is currently under construction.
-
-## Modules
-
-
-- wifi-events
-
-- socket-events
-
-
-
-
-
-## wifi-events
-
-* [wifi-events](#module_wifi-events)
- * _static_
- * [.connectWifi(ssid, password, callback)](#module_wifi-events.connectWifi)
- * [.createSoftAp(ssid, password, callback)](#module_wifi-events.createSoftAp)
- * [.getBssid()](#module_wifi-events.getBssid) ⇒
- * _inner_
- * [~wifiStatusCallback](#module_wifi-events..wifiStatusCallback) : function
-
-
-
-### wifi-events.connectWifi(ssid, password, callback)
-Connect to AP with given ssid and password.
-
-**Kind**: static method of [wifi-events
](#module_wifi-events)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| ssid | | The ssid of the wifi network. |
-| password | | The password of the wifi network. |
-| callback | wifiStatusCallback
| A cb which gets the connect status updates. |
-
-
-
-### wifi-events.createSoftAp(ssid, password, callback)
-Create soft AP with given ssid and password.
-
-**Kind**: static method of [wifi-events
](#module_wifi-events)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| ssid | | The ssid of the wifi network. |
-| password | | The password of the wifi network. |
-| callback | wifiStatusCallback
| A cb which gets the connect status updates. |
-
-
-
-### wifi-events.getBssid() ⇒
-Get the bssid of the current connected wifi AP as formatted as hex string.
-
-**Kind**: static method of [wifi-events
](#module_wifi-events)
-**Returns**: The bssid.
-
-
-### wifi-events~wifiStatusCallback : function
-Callback for wifi status.
-
-**Kind**: inner typedef of [wifi-events
](#module_wifi-events)
-
-| Param | Description |
-| --- | --- |
-| status | The connection status. |
-
-
-
-## socket-events
-
-* [socket-events](#module_socket-events)
- * _static_
- * [.sockets](#module_socket-events.sockets) : [Array.<Socket>
](#module_socket-events..Socket)
- * [.closeSocket(socketOrSockfd)](#module_socket-events.closeSocket)
- * [.sockConnect(ssl, host, port, onConnect, onData, onError, onClose)](#module_socket-events.sockConnect) ⇒ [Socket
](#module_socket-events..Socket)
- * _inner_
- * [~Socket](#module_socket-events..Socket)
- * [.sockfd](#module_socket-events..Socket+sockfd) : number
- * [.onData](#module_socket-events..Socket+onData) : [onDataCB
](#module_socket-events..onDataCB)
- * [~onConnectCB](#module_socket-events..onConnectCB) ⇒ boolean
- * [~onDataCB](#module_socket-events..onDataCB) : function
- * [~onErrorCB](#module_socket-events..onErrorCB) : function
- * [~onCloseCB](#module_socket-events..onCloseCB) : function
-
-
-
-### socket-events.sockets : [Array.<Socket>
](#module_socket-events..Socket)
-An array which holds all active sockets.
-
-**Kind**: static property of [socket-events
](#module_socket-events)
-
-
-### socket-events.closeSocket(socketOrSockfd)
-Flushes buffered writes, shutdowns SSL (if it is a secure socket),
-close the socket, performs the close callback function, removes
-socket from [sockets](#module_socket-events.sockets).
-
-**Kind**: static method of [socket-events
](#module_socket-events)
-
-| Param | Type |
-| --- | --- |
-| socketOrSockfd | [Socket
](#module_socket-events..Socket) \| number
|
-
-
-
-### socket-events.sockConnect(ssl, host, port, onConnect, onData, onError, onClose) ⇒ [Socket
](#module_socket-events..Socket)
-Connects to specified host and port.
-
-**Kind**: static method of [socket-events
](#module_socket-events)
-**Returns**: [Socket
](#module_socket-events..Socket) - The socket.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| ssl | boolean
| If we want to connect via SSL. |
-| host | string
| The remote hostname. |
-| port | number
| The remote port. |
-| onConnect | [onConnectCB
](#module_socket-events..onConnectCB) | A callback which gets called on connect event. |
-| onData | [onDataCB
](#module_socket-events..onDataCB) | A callback which gets called on a data event. |
-| onError | [onErrorCB
](#module_socket-events..onErrorCB) | A callback which gets called on an error event. |
-| onClose | [onCloseCB
](#module_socket-events..onCloseCB) | A callback which gets called on a close event. |
-
-
-
-### socket-events~Socket
-**Kind**: inner class of [socket-events
](#module_socket-events)
-
-* [~Socket](#module_socket-events..Socket)
- * [.sockfd](#module_socket-events..Socket+sockfd) : number
- * [.onData](#module_socket-events..Socket+onData) : [onDataCB
](#module_socket-events..onDataCB)
-
-
-
-#### socket.sockfd : number
-The socket file descriptor.
-
-**Kind**: instance property of [Socket
](#module_socket-events..Socket)
-
-
-#### socket.onData : [onDataCB
](#module_socket-events..onDataCB)
-The onData callback.
-
-**Kind**: instance property of [Socket
](#module_socket-events..Socket)
-
-
-### socket-events~onConnectCB ⇒ boolean
-Callback for connect event.
-
-**Kind**: inner typedef of [socket-events
](#module_socket-events)
-**Returns**: boolean
- If the connection attempt should be retried.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| socket | [Socket
](#module_socket-events..Socket) | The socket. |
-
-
-
-### socket-events~onDataCB : function
-Callback for data event.
-
-**Kind**: inner typedef of [socket-events
](#module_socket-events)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| data | string
| Data that was received on the socket. |
-| sockfd | number
| The socket file descriptor. |
-| length | number
| The length of the data. |
-
-
-
-### socket-events~onErrorCB : function
-Callback for error event.
-
-**Kind**: inner typedef of [socket-events
](#module_socket-events)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| sockfd | number
| The socket file descriptor. |
-
-
-
-### socket-events~onCloseCB : function
-Callback for close event.
-
-**Kind**: inner typedef of [socket-events
](#module_socket-events)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| sockfd | number
| The socket file descriptor. |
-
diff --git a/components/esp32-javascript/modules/esp32-javascript/boot.js b/components/esp32-javascript/modules/esp32-javascript/boot.js
index bb44cdd..70498b5 100644
--- a/components/esp32-javascript/modules/esp32-javascript/boot.js
+++ b/components/esp32-javascript/modules/esp32-javascript/boot.js
@@ -1,22 +1,19 @@
-var configServer = require('./configserver');
-var config = require('./config').config;
-var wifi = require('wifi-events');
-
+Object.defineProperty(exports, "__esModule", { value: true });
+var wifi = require("wifi-events");
+var configServer = require("./configserver");
+var config_1 = require("./config");
errorhandler = function (error) {
console.error(error.stack || error);
startSoftApMode();
};
-
-if (typeof KEY_BUILTIN !== 'undefined') {
+if (typeof KEY_BUILTIN !== "undefined") {
pinMode(KEY_BUILTIN, INPUT);
}
-if (typeof LED_BUILTIN !== 'undefined') {
+if (typeof LED_BUILTIN !== "undefined") {
pinMode(LED_BUILTIN, OUTPUT);
}
-
var configServerStarted = false;
var programLoaded = false;
-
function blink() {
var blinkState = 0;
return setInterval(function () {
@@ -24,12 +21,11 @@ function blink() {
blinkState = blinkState === 0 ? 1 : 0;
}, 333);
}
-
function startSoftApMode() {
console.info("Starting soft ap mode.");
var blinkId = blink();
console.debug("Blinking initialized.");
- wifi.createSoftAp('esp32', '', function (evt) {
+ wifi.createSoftAp("esp32", "", function (evt) {
console.debug("Event received:" + evt);
if (evt.status === 1) {
console.info("SoftAP: Connected");
@@ -40,7 +36,7 @@ function startSoftApMode() {
var timeout = 5;
//stop soft ap wifi after minutes
setTimeout(function () {
- console.info('Stopping soft ap now after ' + timeout + ' minutes.');
+ console.info("Stopping soft ap now after " + timeout + " minutes.");
stopWifi();
clearInterval(blinkId);
// start normal wifi connection attempts
@@ -49,114 +45,124 @@ function startSoftApMode() {
}
else if (evt.status === 0) {
console.info("SoftAP: Disconnected");
- } else {
+ }
+ else {
console.debug("SoftAP: Status " + evt.status);
}
});
}
-
function parseDate(d) {
var day = parseInt(d.substr(5, 2));
- var month = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'].indexOf(d.substr(8, 3));
+ var month = [
+ "Jan",
+ "Feb",
+ "Mar",
+ "Apr",
+ "May",
+ "Jun",
+ "Jul",
+ "Aug",
+ "Sep",
+ "Oct",
+ "Nov",
+ "Dec",
+ ].indexOf(d.substr(8, 3));
var year = parseInt(d.substr(12, 4));
var hour = parseInt(d.substr(17, 2));
var minute = parseInt(d.substr(20, 2));
var second = parseInt(d.substr(23, 2));
-
var date = new Date(Date.UTC(year, month, day, hour, minute, second, 0));
return date;
}
-
function evalScript(content, headers) {
- console.debug('==> Start evaluation:');
+ console.debug("==> Start evaluation:");
digitalWrite(LED_BUILTIN, 0);
- eval(content);
+ eval(content); // this uses headers implicitly (TODO CHECK)
}
-
function connectToWifi() {
digitalWrite(LED_BUILTIN, 1);
-
var retries = 0;
- wifi.connectWifi(config.wlan.ssid, config.wlan.password, function (evt) {
+ wifi.connectWifi(config_1.config.wlan.ssid, config_1.config.wlan.password, function (evt) {
if (evt.status === 0) {
console.info("WIFI: DISCONNECTED");
if (!configServerStarted) {
retries++;
}
if (!configServerStarted && retries === 5) {
- if (config.ota.offline) {
+ if (config_1.config.ota.offline) {
stopWifi();
var programLoadedPrev = programLoaded;
programLoaded = true;
if (!programLoadedPrev) {
- evalScript(el_load('config.script'));
+ evalScript(el_load("config.script"));
}
- } else {
+ }
+ else {
startSoftApMode();
}
}
- } else if (evt.status === 1) {
+ }
+ else if (evt.status === 1) {
if (!programLoaded) {
console.info("WIFI: CONNECTED");
if (!configServerStarted) {
configServer.startConfigServer();
configServerStarted = true;
}
-
retries = 0;
-
- if (config.ota.url) {
+ if (config_1.config.ota.url) {
programLoaded = true;
- console.info('Loading program from: ' + config.ota.url.href);
-
- var headers = null;
- fetch(config.ota.url.href)
+ console.info("Loading program from: " + config_1.config.ota.url.href);
+ var headers;
+ fetch(config_1.config.ota.url.href)
.then(function (r) {
- headers = r.headers;
- return r.text()
- })
+ headers = r.headers;
+ return r.text();
+ })
.then(function (data) {
- if (config.ota.offline) {
- el_store('config.script', data);
- console.info('==> Saved offline script length=' + data.length);
- } else {
- console.info('==> NOT saving offline script');
- }
-
- var dateString = headers.get('Date');
- if (dateString) {
- var now = parseDate(dateString);
- setDateTimeInMillis(now.getTime());
- setDateTimeZoneOffsetInHours(2);
- console.debug('Setting date to ' + new Date());
- }
- evalScript(data, headers);
- })
+ if (config_1.config.ota.offline) {
+ el_store("config.script", data);
+ console.info("==> Saved offline script length=" + data.length);
+ }
+ else {
+ console.info("==> NOT saving offline script");
+ }
+ var dateString = headers.get("Date");
+ if (dateString) {
+ var now = parseDate(dateString);
+ setDateTimeInMillis(now.getTime());
+ setDateTimeZoneOffsetInHours(2);
+ console.debug("Setting date to " + new Date());
+ }
+ evalScript(data, headers);
+ })
.catch(function (error) {
- console.error(error);
- startSoftApMode();
- });
- } else {
- console.error('No OTA (Over-the-air) url specified.');
+ console.error(error);
+ startSoftApMode();
+ });
+ }
+ else {
+ console.error("No OTA (Over-the-air) url specified.");
startSoftApMode();
}
}
- } else if (evt.status === 2) {
+ }
+ else if (evt.status === 2) {
console.info("WIFI: CONNECTING...");
}
});
}
-
function main() {
- if ((typeof KEY_BUILTIN !== 'undefined' && digitalRead(KEY_BUILTIN) == 0) || (typeof config.wlan.ssid === 'undefined')) {
- console.info('Setup key pressed: Start soft ap...');
+ if ((typeof KEY_BUILTIN !== "undefined" && digitalRead(KEY_BUILTIN) == 0) ||
+ typeof config_1.config.wlan.ssid === "undefined") {
+ console.info("Setup key pressed: Start soft ap...");
startSoftApMode();
- } else {
- console.info('Trying to connect to Wifi from JS:');
+ }
+ else {
+ console.info("Trying to connect to Wifi from JS:");
connectToWifi();
}
}
-
module.exports = {
- main: main
-}
\ No newline at end of file
+ main: main,
+};
diff --git a/components/esp32-javascript/modules/esp32-javascript/boot.ts b/components/esp32-javascript/modules/esp32-javascript/boot.ts
new file mode 100644
index 0000000..b75d02b
--- /dev/null
+++ b/components/esp32-javascript/modules/esp32-javascript/boot.ts
@@ -0,0 +1,177 @@
+import wifi = require("wifi-events");
+import configServer = require("./configserver");
+import { config } from "./config";
+
+errorhandler = function (error) {
+ console.error(error.stack || error);
+ startSoftApMode();
+};
+
+if (typeof KEY_BUILTIN !== "undefined") {
+ pinMode(KEY_BUILTIN, INPUT);
+}
+if (typeof LED_BUILTIN !== "undefined") {
+ pinMode(LED_BUILTIN, OUTPUT);
+}
+
+var configServerStarted = false;
+var programLoaded = false;
+
+function blink() {
+ var blinkState = 0;
+ return setInterval(function () {
+ digitalWrite(LED_BUILTIN, blinkState);
+ blinkState = blinkState === 0 ? 1 : 0;
+ }, 333);
+}
+
+function startSoftApMode() {
+ console.info("Starting soft ap mode.");
+ var blinkId = blink();
+ console.debug("Blinking initialized.");
+ wifi.createSoftAp("esp32", "", function (evt) {
+ console.debug("Event received:" + evt);
+ if (evt.status === 1) {
+ console.info("SoftAP: Connected");
+ if (!configServerStarted) {
+ configServer.startConfigServer();
+ configServerStarted = true;
+ }
+ var timeout = 5;
+ //stop soft ap wifi after minutes
+ setTimeout(function () {
+ console.info("Stopping soft ap now after " + timeout + " minutes.");
+ stopWifi();
+ clearInterval(blinkId);
+ // start normal wifi connection attempts
+ connectToWifi();
+ }, timeout * 60 * 1000);
+ } else if (evt.status === 0) {
+ console.info("SoftAP: Disconnected");
+ } else {
+ console.debug("SoftAP: Status " + evt.status);
+ }
+ });
+}
+
+function parseDate(d: string) {
+ var day = parseInt(d.substr(5, 2));
+ var month = [
+ "Jan",
+ "Feb",
+ "Mar",
+ "Apr",
+ "May",
+ "Jun",
+ "Jul",
+ "Aug",
+ "Sep",
+ "Oct",
+ "Nov",
+ "Dec",
+ ].indexOf(d.substr(8, 3));
+ var year = parseInt(d.substr(12, 4));
+ var hour = parseInt(d.substr(17, 2));
+ var minute = parseInt(d.substr(20, 2));
+ var second = parseInt(d.substr(23, 2));
+
+ var date = new Date(Date.UTC(year, month, day, hour, minute, second, 0));
+ return date;
+}
+
+function evalScript(content: string, headers?: Headers) {
+ console.debug("==> Start evaluation:");
+ digitalWrite(LED_BUILTIN, 0);
+ eval(content); // this uses headers implicitly (TODO CHECK)
+}
+
+function connectToWifi() {
+ digitalWrite(LED_BUILTIN, 1);
+
+ var retries = 0;
+ wifi.connectWifi(config.wlan.ssid, config.wlan.password, function (evt) {
+ if (evt.status === 0) {
+ console.info("WIFI: DISCONNECTED");
+ if (!configServerStarted) {
+ retries++;
+ }
+ if (!configServerStarted && retries === 5) {
+ if (config.ota.offline) {
+ stopWifi();
+ var programLoadedPrev = programLoaded;
+ programLoaded = true;
+ if (!programLoadedPrev) {
+ evalScript(el_load("config.script"));
+ }
+ } else {
+ startSoftApMode();
+ }
+ }
+ } else if (evt.status === 1) {
+ if (!programLoaded) {
+ console.info("WIFI: CONNECTED");
+ if (!configServerStarted) {
+ configServer.startConfigServer();
+ configServerStarted = true;
+ }
+
+ retries = 0;
+
+ if (config.ota.url) {
+ programLoaded = true;
+ console.info("Loading program from: " + config.ota.url.href);
+
+ var headers: Headers;
+ fetch(config.ota.url.href)
+ .then(function (r) {
+ headers = r.headers;
+ return r.text();
+ })
+ .then(function (data) {
+ if (config.ota.offline) {
+ el_store("config.script", data);
+ console.info("==> Saved offline script length=" + data.length);
+ } else {
+ console.info("==> NOT saving offline script");
+ }
+
+ var dateString = headers.get("Date");
+ if (dateString) {
+ var now = parseDate(dateString);
+ setDateTimeInMillis(now.getTime());
+ setDateTimeZoneOffsetInHours(2);
+ console.debug("Setting date to " + new Date());
+ }
+ evalScript(data, headers);
+ })
+ .catch(function (error) {
+ console.error(error);
+ startSoftApMode();
+ });
+ } else {
+ console.error("No OTA (Over-the-air) url specified.");
+ startSoftApMode();
+ }
+ }
+ } else if (evt.status === 2) {
+ console.info("WIFI: CONNECTING...");
+ }
+ });
+}
+
+function main() {
+ if (
+ (typeof KEY_BUILTIN !== "undefined" && digitalRead(KEY_BUILTIN) == 0) ||
+ typeof config.wlan.ssid === "undefined"
+ ) {
+ console.info("Setup key pressed: Start soft ap...");
+ startSoftApMode();
+ } else {
+ console.info("Trying to connect to Wifi from JS:");
+ connectToWifi();
+ }
+}
+
+module.exports = {
+ main: main,
+};
diff --git a/components/esp32-javascript/modules/esp32-javascript/config.js b/components/esp32-javascript/modules/esp32-javascript/config.js
index 74d0b75..d1468a1 100644
--- a/components/esp32-javascript/modules/esp32-javascript/config.js
+++ b/components/esp32-javascript/modules/esp32-javascript/config.js
@@ -1,19 +1,16 @@
-var config = {};
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.reloadConfig = exports.config = void 0;
function reloadConfig() {
- config = {
+ exports.config = {
wlan: {
- ssid: el_load('config.ssid'),
- password: el_load('config.password')
+ ssid: el_load("config.ssid"),
+ password: el_load("config.password"),
},
ota: {
- url: urlparse(el_load('config.url')),
- offline: el_load('config.offline') === 'true'
- }
+ url: urlparse(el_load("config.url")),
+ offline: el_load("config.offline") === "true",
+ },
};
}
+exports.reloadConfig = reloadConfig;
reloadConfig();
-
-module.exports = {
- config: config,
- reloadConfig: reloadConfig
-}
\ No newline at end of file
diff --git a/components/esp32-javascript/modules/esp32-javascript/config.ts b/components/esp32-javascript/modules/esp32-javascript/config.ts
new file mode 100644
index 0000000..3c52b0d
--- /dev/null
+++ b/components/esp32-javascript/modules/esp32-javascript/config.ts
@@ -0,0 +1,25 @@
+interface Esp32JsConfig {
+ wlan: {
+ ssid: string;
+ password: string;
+ };
+ ota: {
+ url: any;
+ offline: boolean;
+ };
+}
+
+export var config: Esp32JsConfig;
+export function reloadConfig() {
+ config = {
+ wlan: {
+ ssid: el_load("config.ssid"),
+ password: el_load("config.password"),
+ },
+ ota: {
+ url: urlparse(el_load("config.url")),
+ offline: el_load("config.offline") === "true",
+ },
+ };
+}
+reloadConfig();
diff --git a/components/esp32-javascript/modules/esp32-javascript/configserver.js b/components/esp32-javascript/modules/esp32-javascript/configserver.js
index b26726b..5b6a382 100644
--- a/components/esp32-javascript/modules/esp32-javascript/configserver.js
+++ b/components/esp32-javascript/modules/esp32-javascript/configserver.js
@@ -1,102 +1,120 @@
-var configManager = require('./config');
-var http = require('./http');
-var httpServer = http.httpServer;
-
-var requestHandler = [];
-var baExceptionPathes = [];
-
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.startConfigServer = exports.redirect = exports.getHeader = exports.baExceptionPathes = exports.requestHandler = void 0;
+var configManager = require("./config");
+var http_1 = require("./http");
+exports.requestHandler = [];
+exports.baExceptionPathes = [];
function getHeader(statusCode, additionalHeaders) {
- return ['HTTP/1.1 ', statusCode, ' OK\r\n',//
- 'Connection: close\r\n',//
- (additionalHeaders ? additionalHeaders : ''),
- '\r\n'].join('');
+ return [
+ "HTTP/1.1 ",
+ statusCode,
+ " OK\r\n",
+ "Connection: close\r\n",
+ additionalHeaders ? additionalHeaders : "",
+ "\r\n",
+ ].join("");
}
-
+exports.getHeader = getHeader;
function redirect(res, location) {
- res.end(getHeader(302, 'Location: ' + location + '\r\n'));
+ res.end(getHeader(302, "Location: " + location + "\r\n"));
}
-
+exports.redirect = redirect;
function page(res, headline, text, cb) {
- res.write(getHeader(200, 'Content-type: text/html\r\n'));
- res.write('esp32-javascript');
+ res.write(getHeader(200, "Content-type: text/html\r\n"));
+ res.write("esp32-javascript");
res.write('');
res.write('');
res.write('');
res.write(headline);
- res.write('
');
+ res.write("");
if (Array.isArray(text)) {
- text.forEach(function (t) { res.write(t) });
- } else {
+ text.forEach(function (t) {
+ res.write(t);
+ });
+ }
+ else {
res.write(text);
}
- res.end(' \r\n\r\n', cb);
+ res.end("\r\n\r\n", cb);
}
-
function startConfigServer() {
- console.info('Starting config server.');
+ console.info("Starting config server.");
var defaultConfig = getDefaultConfig();
- var authString = ('Basic ' + btoa(defaultConfig.basicAuthUsername + ':' + defaultConfig.basicAuthPassword));
- httpServer(80, false, function (req, res) {
- if (req.headers['authorization'] !== authString && baExceptionPathes.indexOf(req.path) < 0) {
- console.debug('401 response');
+ var authString = "Basic " +
+ btoa(defaultConfig.basicAuthUsername + ":" + defaultConfig.basicAuthPassword);
+ http_1.httpServer(80, false, function (req, res) {
+ if (req.headers["authorization"] !== authString &&
+ exports.baExceptionPathes.indexOf(req.path) < 0) {
+ console.debug("401 response");
res.write(getHeader(401, 'WWW-Authenticate: Basic realm="Enter credentials"\r\n'));
- res.end('401 Unauthorized');
- } else if (req.path === '/restart' && req.method === 'POST'){
- page(res, 'Restarting...
Home', '', function () { setTimeout(restart, 1000) });
- } else if (req.path === '/setup' || req.path === '/restart') {
- if (req.method === 'GET') {
- page(res, 'Setup', ['