Debug info fixes
This commit is contained in:
parent
5de45af0e5
commit
f34a3039c5
21
.env.example
Normal file
21
.env.example
Normal file
@ -0,0 +1,21 @@
|
||||
# Either "production" or "development"
|
||||
|
||||
NODE_ENV = "development"
|
||||
|
||||
# Only for production
|
||||
# certificate and private key for HTTPS
|
||||
|
||||
CERT_PATH = "/path/to/fullchain.pem"
|
||||
PRIVATE_KEY_PATH = "/path/to/privkey.pem"
|
||||
|
||||
# Database
|
||||
|
||||
DB_USER_NAME = ""
|
||||
DB_USER_PASSWORD = ""
|
||||
DB_SERVER = ""
|
||||
MONGO_CONNECTION_STRING = "mongodb+srv://$DB_USER_NAME:$DB_USER_PASSWORD@$DB_SERVER/autocatdev?retryWrites=true&w=majority"
|
||||
|
||||
# JWT secrets
|
||||
|
||||
JWT_SECRET_AUTH = ""
|
||||
JWT_SECRET_SHARED_REPORT = ""
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,4 @@
|
||||
.DS_Store
|
||||
|
||||
node_modules/
|
||||
.env
|
||||
@ -101,7 +101,7 @@ class AvtocodProvider {
|
||||
} catch(ex) {
|
||||
ex.debugInfo = {
|
||||
autocod: {
|
||||
fields: 0n,
|
||||
fields: 0,
|
||||
error: ex.message
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,36 +12,41 @@ const from = 'search';
|
||||
|
||||
class NomerogramProvider {
|
||||
static async getGroups(number) {
|
||||
let timestamp = Math.floor(Date.now() / 1000);
|
||||
let secretSource = appId + number + deviceId + from + timestamp + secretSuffix;
|
||||
|
||||
let hash = crypto.createHash('sha256');
|
||||
hash.update(secretSource);
|
||||
let secret = hash.digest('hex');
|
||||
console.log('secret: ', secret);
|
||||
|
||||
let url = `${baseUrl}/group/list?from=${from}&carplate=${number}×tamp=${timestamp}&secret=${secret}&app_id=${appId}&device_id=${deviceId}`;
|
||||
let result = await fetch(utf8.encode(url));
|
||||
let json = await result.json();
|
||||
|
||||
if(!json.success) {
|
||||
throw Error(json.message);
|
||||
//return [];
|
||||
try {
|
||||
let timestamp = Math.floor(Date.now() / 1000);
|
||||
let secretSource = appId + number + deviceId + from + timestamp + secretSuffix;
|
||||
|
||||
let hash = crypto.createHash('sha256');
|
||||
hash.update(secretSource);
|
||||
let secret = hash.digest('hex');
|
||||
console.log('secret: ', secret);
|
||||
|
||||
let url = `${baseUrl}/group/list?from=${from}&carplate=${number}×tamp=${timestamp}&secret=${secret}&app_id=${appId}&device_id=${deviceId}`;
|
||||
let result = await fetch(utf8.encode(url));
|
||||
let json = await result.json();
|
||||
|
||||
if(!json.success) {
|
||||
throw Error(json.message);
|
||||
//return [];
|
||||
}
|
||||
|
||||
return json.data.groups.map(g => {
|
||||
return {
|
||||
id: g.group_id,
|
||||
url: g.group_url,
|
||||
price: g.price,
|
||||
date: Utils.parseDate(g.date),
|
||||
mileage: g.mileage,
|
||||
region: g.region_name,
|
||||
city: g.city_name,
|
||||
adDescription: g.description,
|
||||
photos: g.photos.map(p => p.src.default)
|
||||
};
|
||||
});
|
||||
} catch(ex) {
|
||||
ex.debugInfo = { nomerogram: { fields: 0, error: ex.message } };
|
||||
throw ex;
|
||||
}
|
||||
|
||||
return json.data.groups.map(g => {
|
||||
return {
|
||||
id: g.group_id,
|
||||
url: g.group_url,
|
||||
price: g.price,
|
||||
date: Utils.parseDate(g.date),
|
||||
mileage: g.mileage,
|
||||
region: g.region_name,
|
||||
city: g.city_name,
|
||||
adDescription: g.description,
|
||||
photos: g.photos.map(p => p.src.default)
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@ class RsaProvider {
|
||||
}
|
||||
|
||||
if(!json.processId) {
|
||||
throw Error('Process ID is null');
|
||||
throw Error('Process ID is null');
|
||||
}
|
||||
|
||||
return json.processId;
|
||||
|
||||
@ -66,9 +66,9 @@ class Vin01Provider {
|
||||
let vehicle = new Vehicle();
|
||||
vehicle.vin1 = Utils.cyrillicToLatin(vin);
|
||||
vehicle.debugInfo = {
|
||||
vin01vin: { fields: 0n, error: null },
|
||||
vin01history: { fields: 0n, error: history.reason },
|
||||
vin01base: { fields: 0n, error: base.reason }
|
||||
vin01vin: { fields: 0, error: null },
|
||||
vin01history: { fields: 0, error: history.reason },
|
||||
vin01base: { fields: 0, error: base.reason }
|
||||
}
|
||||
return vehicle;
|
||||
} else if(base.status == 'rejected') {
|
||||
@ -76,8 +76,8 @@ class Vin01Provider {
|
||||
let vehicle = Vehicle.fromVin01History(history.value);
|
||||
vehicle.number = number;
|
||||
Object.assign(vehicle.debugInfo, {
|
||||
vin01vin: { fields: 0n, error: null },
|
||||
vin01base: { fields: 0n, error: base.reason }
|
||||
vin01vin: { fields: 0, error: null },
|
||||
vin01base: { fields: 0, error: base.reason }
|
||||
});
|
||||
return vehicle;
|
||||
} else if(history.status == 'rejected') {
|
||||
@ -85,8 +85,8 @@ class Vin01Provider {
|
||||
let vehicle = Vehicle.fromVin01Base(base.value);
|
||||
vehicle.number = number;
|
||||
Object.assign(vehicle.debugInfo, {
|
||||
vin01vin: { fields: 0n, error: null },
|
||||
vin01history: { fields: 0n, error: history.reason }
|
||||
vin01vin: { fields: 0, error: null },
|
||||
vin01history: { fields: 0, error: history.reason }
|
||||
});
|
||||
return vehicle;
|
||||
} else {
|
||||
@ -122,7 +122,7 @@ class Vin01Provider {
|
||||
}
|
||||
}
|
||||
|
||||
Object.assign(historyVehicle.debugInfo, { vin01vin: { fields: 0n, error: null } });
|
||||
Object.assign(historyVehicle.debugInfo, { vin01vin: { fields: 0, error: null } });
|
||||
Object.assign(historyVehicle.debugInfo, baseVehicle.debugInfo);
|
||||
|
||||
historyVehicle.number = number;
|
||||
@ -130,10 +130,10 @@ class Vin01Provider {
|
||||
}
|
||||
} catch(ex) {
|
||||
ex.debugInfo = {
|
||||
vin01vin: { fields: 0n, error: ex.message },
|
||||
vin01history: { fields: 0n, error: 'Not applicable' },
|
||||
vin01base: { fields: 0n, error: 'Not applicable' }
|
||||
}
|
||||
vin01vin: { fields: 0, error: ex.message },
|
||||
vin01history: { fields: 0, error: 'Not applicable (VIN was not found)' },
|
||||
vin01base: { fields: 0, error: 'Not applicable (VIN was not found)' }
|
||||
};
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
27
index.js
27
index.js
@ -10,22 +10,31 @@ const jwt = require('./middleware/jwt');
|
||||
const https = require('https');
|
||||
const fs = require('fs');
|
||||
const compression = require('compression');
|
||||
const dotenv = require('dotenv');
|
||||
const dotenvExpand = require('dotenv-expand');
|
||||
|
||||
const httpsServer = https.createServer({
|
||||
key: fs.readFileSync('/etc/letsencrypt/live/vps.aliencat.pro/privkey.pem'),
|
||||
cert: fs.readFileSync('/etc/letsencrypt/live/vps.aliencat.pro/fullchain.pem')
|
||||
}, app);
|
||||
let dotenvConf = dotenv.config();
|
||||
dotenvExpand(dotenvConf);
|
||||
|
||||
console.log(process.env);
|
||||
|
||||
app.use(compression());
|
||||
app.use(bodyParser.json());
|
||||
//app.use(expressMongoDb('mongodb://autocat_user:autocat#321@192.168.1.1:27017/autocatdev'));
|
||||
app.use(expressMongoDb('mongodb://autocat_user:autocat#321@127.0.0.1:27017/autocatdev'));
|
||||
app.use(expressMongoDb(process.env.MONGO_CONNECTION_STRING));
|
||||
app.use(bearerToken());
|
||||
app.use(jwt({ secret: '#IWantToBelieve', exclude: ['/user/signup', '/user/login', '/vehicles/shared_report'] }));
|
||||
app.use(jwt({ secret: process.env.JWT_SECRET_AUTH, exclude: ['/user/signup', '/user/login', '/vehicles/shared_report'] }));
|
||||
|
||||
app.use('/user', users);
|
||||
app.use('/vehicles', vehicles);
|
||||
app.use('/events', events);
|
||||
|
||||
//app.listen(3000);
|
||||
httpsServer.listen(8443);
|
||||
if(process.env.NODE_ENV == 'production') {
|
||||
const httpsServer = https.createServer({
|
||||
key: fs.readFileSync(process.env.PRIVATE_KEY_PATH),
|
||||
cert: fs.readFileSync(process.env.CERT_PATH)
|
||||
}, app);
|
||||
httpsServer.listen(8443);
|
||||
} else {
|
||||
app.listen(3000);
|
||||
}
|
||||
|
||||
|
||||
@ -63,7 +63,7 @@ class Vehicle {
|
||||
|
||||
v.debugInfo = {
|
||||
autocod: {
|
||||
fields: 0n,
|
||||
fields: 0,
|
||||
error: null
|
||||
}
|
||||
};
|
||||
@ -106,7 +106,7 @@ class Vehicle {
|
||||
|
||||
v.debugInfo = {
|
||||
vin01history: {
|
||||
fields: 0n,
|
||||
fields: 0,
|
||||
error: null
|
||||
}
|
||||
};
|
||||
@ -167,7 +167,7 @@ class Vehicle {
|
||||
|
||||
v.debugInfo = {
|
||||
vin01base: {
|
||||
fields: 0n,
|
||||
fields: 0,
|
||||
error: null
|
||||
}
|
||||
};
|
||||
|
||||
2573
package-lock.json
generated
2573
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -14,6 +14,8 @@
|
||||
"compress": "^0.99.0",
|
||||
"compression": "^1.7.4",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^8.2.0",
|
||||
"dotenv-expand": "^5.1.0",
|
||||
"express": "^4.17.1",
|
||||
"express-bearer-token": "^2.4.0",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
|
||||
@ -33,7 +33,13 @@ router.post('/check', async (req, res) => {
|
||||
let vin01Promise = Vin01Provider.getReport(number, googleIdToken);
|
||||
all.push(vin01Promise);
|
||||
} else {
|
||||
all.push(Promise.reject(''));
|
||||
all.push(Promise.reject({
|
||||
debugInfo: {
|
||||
vin01vin: { fields: 0, error: 'No auth token' },
|
||||
vin01history: { fields: 0, error: 'No auth token' },
|
||||
vin01base: { fields: 0, error: 'No auth token' }
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
all.push(NomerogramProvider.getGroups(number));
|
||||
@ -65,7 +71,7 @@ router.post('/check', async (req, res) => {
|
||||
|
||||
if(nomerogram.status == 'fulfilled') {
|
||||
vehicle.ads = nomerogram.value;
|
||||
Object.assign(vehicle.debugInfo, { fields: 0n, error: null });
|
||||
Object.assign(vehicle.debugInfo, { nomerogram: { fields: 0, error: null } });
|
||||
} else {
|
||||
Object.assign(vehicle.debugInfo, nomerogram.reason.debugInfo);
|
||||
console.error('nomerogram error: ', nomerogram.reason);
|
||||
@ -160,7 +166,7 @@ router.get('/regions', (req, res) => {
|
||||
|
||||
router.get('/shared_report', cors({ origin: 'https://auto.aliencat.pro' }), async (req, res) => {
|
||||
try {
|
||||
let { plateNumber } = jwt.verify(req.query.token, '#TheTruthIsOutThere');
|
||||
let { plateNumber } = jwt.verify(req.query.token, process.env.JWT_SECRET_SHARED_REPORT);
|
||||
let collection = req.db.collection('vehicles');
|
||||
let vehicles = await collection.find({ number: plateNumber }).toArray();
|
||||
if(vehicles.length > 0) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user