Hello everyone! This is the repository of the site grechka.com. Visit grechka.com here!
- Table of contents
- Motivation
- Build status
- Badges
- Code style
- Screenshots
- Tech/framework used
- Features
- Code Example
- Fast usage
- Contribute
- License
The goal of this project is to create a website that helps customers find the best prices for buckwheat.
Here you can see build status of continuous integration:
Other badges
We are using Codacy to automate our code quality.
- Main page
- Filters
- Show products with filters
- About page
- Filters on adaptive screen
Built with
On the site you can find the cheapest buckwheat, sort by price segment, by price, by weight, in direct and reverse order and get the lowest price in recent times.
- Product schema
const mongoose = require('mongoose');
const productSchema = mongoose.Schema({
productName: String,
categoryId: mongoose.Schema.Types.ObjectId,
manufacturerId: mongoose.Schema.Types.ObjectId,
weight: Number,
price: Number,
priceSegment: String,
productURL: String,
productImgURL: String,
description: String,
});
- Server
'use strict';
const http = require('http');
const FileManager = require('./fileManager').FileManager;
const Database = require('./Database').Database;
const config = require('./config.json');
const setNewProduct = require('./setNewProduct').setNewProduct;
const minPriceByDay = require('./minPriceByDay').minPriceByDay;
const fileManager = new FileManager();
const dbVar = config.development.database;
const db = new Database(dbVar);
//types of request extensions
const mime = {
'html': 'text/html',
'js': 'application/javascript',
'css': 'text/css',
'png': 'image/png',
'ico': 'image/x-icon',
'/date': 'text/plain',
'/getProdData': 'text/plain',
'svg': 'image/svg+xml',
};
class Server {
constructor(port) {
const server = http.createServer();
server.listen(port, () => {
console.log('Server running on port: ' + port);
});
server.on('request', this.handleRequest);
}
//function for handling requests
async handleRequest(req, res) {
let data = null;
const url = req.url;
let name = url;
const method = req.method;
let extention = url.split('.')[1];
if (method === 'GET') {
if (url === '/') {
extention = 'html';
name = '/public/index.html';
} else if (url === '/about') {
extention = 'html';
name = '/public/about.html';
} else if (url === '/getProdData') {
console.log('/getProdData');
data = [];
const products = await db.getAllByTableName('Product');
for (const product of products) {
const category = (await db.find('Category', { _id: product.categoryId })).categoryType;
const isCompanyName = (await db.find('Manufacturer', { _id: product.manufacturerId }));
if (isCompanyName) {
data.push(setNewProduct(product, category, isCompanyName.companyName));
} else {
data.push(setNewProduct(product, category));
}
}
console.log(data);
data = JSON.stringify(data);
} else if (url === '/getGraphicData') {
console.log('/getGraphicData');
const history = await db.getAllByTableName('History');
data = JSON.stringify(minPriceByDay(history));
}
const typeAns = mime[extention];
if (!data) data = await fileManager.readFile('.' + name);
if (!data) {
console.log('no such file => ' + name);
//handle if no page
const pageNotFound = await fileManager.readFile('./public/pageNotFound.html');
res.writeHead(404, { 'Content-Type': 'text/html; charset=utf-8' });
res.write(pageNotFound);
} else if (typeof data === 'number') {
console.log('error occured => ' + name);
res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' });
} else {
res.writeHead(200, { 'Content-Type': `${typeAns}; charset=utf-8` });
res.write(data);
}
res.end();
} else if (method === 'POST') {
console.log('POST');
}
}
}
module.exports = { Server };
Just open the link in the description and enjoy your pastime.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Also look at the CONTRIBUTING.md.
MIT © mezidia