MagicMirror/js/server.js
Sergey Morozov 86fdd91597 Restructured Test Suite
- separated tests into e2e and unit directories
- created configs directory structure to support test framework
- added/modified `npm run test`, `npm run test:unit` and `npm run test:e2e` to target all, unit and e2e tests respectively
- modified some of the test names to be more descriptive

New structure of the Test Suite has following directory tree:

```
tests
├── configs
│   ├── env.js
│   └── modules
│       ├── clock
│       │   ├── clock_12hr.js
│       │   ├── clock_24hr.js
│       │   └── clock_showPeriodUpper.js
│       └── helloworld
│           └── helloworld.js
├── e2e
│   ├── env_spec.js
│   └── modules
│       ├── clock_spec.js
│       └── helloworld_spec.js
└── unit
    ├── functions
    │   └── cmp_versions_spec.js
    └── global_vars
        └── root_path_spec.js
```
2017-01-31 11:08:53 -08:00

65 lines
2.1 KiB
JavaScript

/* Magic Mirror
* Server
*
* By Michael Teeuw http://michaelteeuw.nl
* MIT Licensed.
*/
var express = require("express");
var app = require("express")();
var server = require("http").Server(app);
var io = require("socket.io")(server);
var path = require("path");
var ipfilter = require("express-ipfilter").IpFilter;
var fs = require("fs");
var helmet = require("helmet");
var Server = function(config, callback) {
console.log("Starting server op port " + config.port + " ... ");
server.listen(config.port, config.address ? config.address : null);
app.use(function(req, res, next) {
var result = ipfilter(config.ipWhitelist, {mode: "allow", log: false})(req, res, function(err) {
if (err === undefined) {
return next();
}
console.log(err.message);
res.status(403).send("This device is not allowed to access your mirror. <br> Please check your config.js or config.js.sample to change this.");
});
});
app.use(helmet());
app.use("/js", express.static(__dirname));
app.use("/config", express.static(path.resolve(global.root_path + "/config")));
app.use("/css", express.static(path.resolve(global.root_path + "/css")));
app.use("/fonts", express.static(path.resolve(global.root_path + "/fonts")));
app.use("/modules", express.static(path.resolve(global.root_path + "/modules")));
app.use("/vendor", express.static(path.resolve(global.root_path + "/vendor")));
app.use("/translations", express.static(path.resolve(global.root_path + "/translations")));
app.use("/tests/configs", express.static(path.resolve(global.root_path + "/tests/configs")));
app.get("/version", function(req,res) {
res.send(global.version);
});
app.get("/", function(req, res) {
var html = fs.readFileSync(path.resolve(global.root_path + "/index.html"), {encoding: "utf8"});
html = html.replace("#VERSION#", global.version);
configFile = "config/config.js";
if (typeof(global.configuration_file) !== "undefined") {
configFile = global.configuration_file;
}
html = html.replace("#CONFIG_FILE#", configFile);
res.send(html);
});
if (typeof callback === "function") {
callback(app, io);
}
};
module.exports = Server;