metatech-university / nodejs-pure Goto Github PK
View Code? Open in Web Editor NEWPure NodeJS application server
License: MIT License
Pure NodeJS application server
License: MIT License
В файле db.js присутствует следующий код
async read(id, fields = ['*']) {
const names = fields.join(', ');
const sql = `SELECT ${names} FROM ${table}`;
if (!id) return pool.query(sql);
return pool.query(`${sql} WHERE id = $1`, [id]);
}
Здесь может быть уязвимость связанная с SQL инъекцией. Поскольку запрос в базу данных использует конкатенацию строк, которые ни как не валидируются. Конечно уязвимость зависит от того, как этим методом пользоваться. Но вдруг кто то вызовет его не так, как нам хочется.
There was a discussion about custom domain errors at the course meeting (QA 28/02/2023).
Proposed variants were separate class per error or general DomainError
class with an internal map of allowed messages.
Instead, I propose having one class per domain with factories of allowed errors.
class DomainError extends Error {
...
}
class MessengerError extends DomainError {
...
static invalidPermission() {
return new MessengerError('Permission denied');
}
static notFound() {
return new MessengerError('Not found');
}
// and so on...
}
This neither requires defining a class per each error (1 proposal) nor requires additional functionality to check if a general purpose error received an allowed message (2 proposal).
This also adds static checks and autocompletion.
Line 179 in 9ff24ad
Здравствуйте, подскажите пожалуйста, почему функция называется serveStatic, ведь по сути она ничего не сервает? Ну то есть сервер в ней не создается, дальше по коду, где она используется в классе, мы ее кладем в метод this.staticHandler = serveStatic(staticPath);
Возможно эту функцию корректнее назвать staticHandler?
Line 89 in ac7505c
As it was discussed in the meeting, API endpoints from Nodejs-Application have wrong root directory(Nodejs-Pure directory).
For example this endpoint. In this case fs
thinks he is in Nodejs-Pure directory just now and upoaded file will be written simple in the NodeJs-Pure.
So the resolve of this problem is just to change root path in vm Sandbox
.
I attempted to organize the code structure in my pet project based on the examples from this repository: https://github.com/metatech-university/NodeJS-Application/pull/4/files. However, I faced issues with accessing the 'lib' and 'domain' folders.
To fix this, I added the following code to my main.js file:
const sandbox = {
console, common, api, db: null, lib: {}, domain: {}
};
sandbox.lib = Object.freeze(await loadDir(libPath, sandbox));
sandbox.domain = Object.freeze(await loadDir(domainPath, sandbox));
However, this approach caused issues where the 'domain' folder was not visible from the 'lib' folder, and neither folder could access itself. But from api folder have a access for both folder
For example, I had a function located in the 'domain' folder at domain/Chat/get.js:
async (ctx, name) => {
const { repository } = domain.Chat;
const chat = await repository.get(ctx, name);
if (!chat) throw new domain.Errors.NotFoundError('No such chat', { name });
return chat;
};
This function attempted to retrieve a repository from the 'domain/Chat/repository/get.js' module, but returned 'undefined'.
To be compatible with Metarhia api, example: https://github.com/metarhia/Example/tree/master/application/api
Line 18 in 55dce31
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.