Real-time communication with frontend
- Frontend shows heatmap of most visit places - Maximum accuracy can now be set - Fix bug where battery chart filtered values wrongly
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
import bodyParser = require('body-parser');
|
||||
import { bold } from 'chalk';
|
||||
import * as cors from 'cors';
|
||||
import { config as dconfig } from 'dotenv';
|
||||
import * as express from 'express';
|
||||
import * as figlet from 'figlet';
|
||||
import * as mongoose from 'mongoose';
|
||||
import * as cors from 'cors';
|
||||
import { exit } from 'process';
|
||||
import * as winston from 'winston';
|
||||
import { RabbitMQ } from './lib/rabbit';
|
||||
|
||||
import { config } from './config';
|
||||
import { DeleteUser, GetUser, LoginUser, MW_User, PatchUser } from './endpoints/user';
|
||||
import { GetBeat, GetBeatStats } from './endpoints/beat';
|
||||
import { GetPhone, PostPhone } from './endpoints/phone';
|
||||
import { DeleteUser, GetUser, LoginRabbitUser, LoginUser, MW_User, PatchUser, Resource, Topic, VHost } from './endpoints/user';
|
||||
import { hashPassword, randomPepper, randomString } from './lib/crypto';
|
||||
import { RabbitMQ } from './lib/rabbit';
|
||||
import { UserType } from './models/user/user.interface';
|
||||
import { User } from './models/user/user.model';
|
||||
import { GetPhone, PostPhone } from './endpoints/phone';
|
||||
import { GetBeat, GetBeatStats } from './endpoints/beat';
|
||||
|
||||
// Load .env
|
||||
dconfig({ debug: true, encoding: 'UTF-8' });
|
||||
@@ -107,6 +107,7 @@ async function run() {
|
||||
await User.create({
|
||||
name: 'admin',
|
||||
password: await hashPassword(randomPassword + salt + randomPepper()),
|
||||
brokerToken: randomString(16),
|
||||
salt,
|
||||
createdAt: Date.now(),
|
||||
lastLogin: 0,
|
||||
@@ -119,13 +120,6 @@ async function run() {
|
||||
logger.debug("At least one admin user already exists, skip.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Message broker
|
||||
*/
|
||||
rabbitmq = new RabbitMQ();
|
||||
await rabbitmq.init();
|
||||
logger.info("Connected with message broker.");
|
||||
|
||||
/**
|
||||
* HTTP server
|
||||
*/
|
||||
@@ -143,14 +137,22 @@ async function run() {
|
||||
});
|
||||
|
||||
app.get('/', (req, res) => res.status(200).send('OK'));
|
||||
|
||||
// User authentication
|
||||
app.post('/user/login', (req, res) => LoginUser(req, res));
|
||||
app.get('/user/rabbitlogin', (req, res) => LoginRabbitUser(req, res));
|
||||
app.get('/user/vhost', (req, res) => VHost(req, res));
|
||||
app.get('/user/resource', (req, res) => Resource(req, res));
|
||||
app.get('/user/topic', (req, res) => Topic(req, res));
|
||||
|
||||
// Basic user actions
|
||||
app.get('/user/', MW_User, (req, res) => GetUser(req, res));
|
||||
app.get('/user/:id', MW_User, (req, res) => GetUser(req, res));
|
||||
app.patch('/user/:id', MW_User, (req, res) => PatchUser(req, res));
|
||||
app.delete('/user/:id', MW_User, (req, res) => DeleteUser(req, res));
|
||||
app.post('/user/login', (req, res) => LoginUser(req, res));
|
||||
|
||||
app.get('/phone', MW_User, (req, res) => GetPhone(req, res));
|
||||
app.get('/phone/:id', MW_User, (req, res) => GetPhone(req, res));
|
||||
app.get('/phone', MW_User, (req, res) => GetPhone(req, res));
|
||||
app.post('/phone', MW_User, (req, res) => PostPhone(req, res));
|
||||
|
||||
app.get('/beat/', MW_User, (req, res) => GetBeat(req, res));
|
||||
@@ -159,6 +161,13 @@ async function run() {
|
||||
app.listen(config.http.port, config.http.host, () => {
|
||||
logger.info(`HTTP server is running at ${config.http.host}:${config.http.port}`);
|
||||
});
|
||||
|
||||
/**
|
||||
* Message broker
|
||||
*/
|
||||
rabbitmq = new RabbitMQ();
|
||||
await rabbitmq.init();
|
||||
logger.info("Connected with message broker.");
|
||||
}
|
||||
|
||||
run();
|
||||
Reference in New Issue
Block a user