# Icoms server esp32

This project have to purpose to offer a very ligth weight lowjs server package with basics functions.

## Install

```bash
$ npm i icoms-server-esp32
```

## Usage

Before starting the server, make sure you have configured the logs in the right place

```javascript
const { Server, Device, Logger, isOnEsp32, LogType } = require("../modules/index");
const { PassThrough } = require("stream");
const { join } = require("path");
const { setPassword, getPassword } = require("./settings");

//Device parameters are optional, use them to override the default configuration
const server = Server();
const device = Device();

Logger.init({
  folderAbsolutePath: `${isOnEsp32 ? "" : "put the absolute path from your computer to file_system folder"}/logsFolderName`,
  logLevel: LogType.DEBUG,
});

/**
 * Routes and functions below
 * */

server.setDirectory(join(__dirname, "..", "build"), "index.html");
server.start(80);
```

## Logger

Useful to know what happened
To use it, initialize it first with the disired configuration at the beginning of the main, then call `getLogger()`. You have the possibility to mention a string which will be displayed at each call of the logger. On your new logger, you have 6 log methods, each corresponding to a log level, by order of importance :

- trace
- debug
- info
- warn
- error
- fatal

## Routing

request on :

- /doc : return doc about the server
- /api/... : return what you configure with get, post, deleteRequest
- /update : send by a post method the .dat file
- /setting
  - /wifi
    - GET: will return wifi data
    - POST: send in body
      ```json
      {
        "ssid": "newWifiName", //Must be at least 4 char long
        "password": "newPassord" //Must be at least 4 char long
      }
      ```
- / : other call will return files from front if found
