taapi-cache
Version:
TAAPI.IO Cache Package. A convenient way to fetch candles, store them and reuse them.
37 lines (28 loc) • 1.13 kB
JavaScript
const express = require("express");
const RESTSchema = require("./schema/RESTSchema");
const bodyParser = require('body-parser');
const authentication = require("./middleware/Authentication");
const config = require("./config/config");
const chalk = require("chalk");
const scheduler = require("./engine/Scheduler");
console.log(chalk.cyan("Starting TAAPI.IO Cache Server..."));
const api = express(); // Validate the config environment
config.validateEnvironment();
api.use(bodyParser.json()); // to support JSON-encoded bodies
api.use(bodyParser.urlencoded({
// to support URL-encoded bodies
extended: true
}));
api.use(authentication);
console.log(chalk.cyan("Setting up the RESTful Endpoints..."));
const restSchema = new RESTSchema(api);
restSchema.configureEndpoints();
api.use(function (err, req, res, next) {
console.error(err.stack);
res.status(500).send('Something went wrong!!');
});
console.log(chalk.cyan("Starting up scheduler..."));
scheduler.startMonitor();
api.listen(config.server.port, () => {
console.log(chalk.green(`TAAPI.IO Cache Server Running on port ${config.server.port}!`));
});