upload files into repos
This commit is contained in:
commit
8fa615212c
79
codeExample.js
Normal file
79
codeExample.js
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
const backend = require('index');
|
||||||
|
|
||||||
|
// Создаём экземпляр класса backend.Main
|
||||||
|
var server = new backend.Main(
|
||||||
|
false // Отобразить в заголовках информацию о текущем фреймворке
|
||||||
|
);
|
||||||
|
// Настраиваем сессию (опционально)
|
||||||
|
server.session = (params, sessionData) => {
|
||||||
|
sessionData._setValue('example', 1); // Задать значение
|
||||||
|
console.log(sessionData.example); // Получить значение из сессии
|
||||||
|
sessionData._remove('example'); // Убрать значение
|
||||||
|
return 1; // Успешно
|
||||||
|
return 'Example error'; // Пример ошибки
|
||||||
|
};
|
||||||
|
// Настраиваем вывод
|
||||||
|
server.error = (error) => ({
|
||||||
|
mainbody : { error },
|
||||||
|
headers : {
|
||||||
|
errored : 1
|
||||||
|
},
|
||||||
|
cookies : {
|
||||||
|
avava : 1
|
||||||
|
},
|
||||||
|
// redirect_uri: ''; // if want redirect to another url
|
||||||
|
code: 400
|
||||||
|
});
|
||||||
|
server.resposne = (response) => ({
|
||||||
|
mainbody : { response },
|
||||||
|
headers : {
|
||||||
|
errored: 0
|
||||||
|
},
|
||||||
|
cookies : {},
|
||||||
|
// redirect_uri: ''; // if want redirect to another url
|
||||||
|
code: 200
|
||||||
|
});
|
||||||
|
server.paramsError = (required, additional) => ({ required, additional });
|
||||||
|
|
||||||
|
// Создаём класс группы методов
|
||||||
|
class ExampleMethodGroup extends backend.Group {
|
||||||
|
handler (params, session) { // Путевая обработка
|
||||||
|
session._setValue('example', 1); // Задать значение
|
||||||
|
console.log(session.example); // Получить значение из сессии
|
||||||
|
session._remove('example'); // Убрать значение
|
||||||
|
return 1; // Успешно
|
||||||
|
return 'Example error' // Пример ошибки
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Создаём класс метода
|
||||||
|
class ExampleMethod extends backend.Method {
|
||||||
|
/*
|
||||||
|
var result = this.MainObject.call(method : string, params : object) // Вызов подключённого метода
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Обработчик параметров
|
||||||
|
execute (params) {
|
||||||
|
return params.text;
|
||||||
|
throw { code: 'EXAMPLE_ERROR', details: new Object() };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var exampleMethod = new ExampleMethod('/example', {
|
||||||
|
text: {
|
||||||
|
required : true,
|
||||||
|
type : backend.types.string,
|
||||||
|
conversion : false,
|
||||||
|
// values : [],
|
||||||
|
min_length : 1,
|
||||||
|
max_length : 255,
|
||||||
|
// allow_methods : ['post'],
|
||||||
|
// allow_params : ['json'],
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Привяжем метод к группе
|
||||||
|
exampleMethod.group(ExampleMethodGroup);
|
||||||
|
// Привяжем метод к основному проекту
|
||||||
|
server.method(exampleMethod);
|
||||||
|
|
||||||
|
// Запускаем сервер
|
||||||
|
server.server().listen(8080);
|
8
components/Main.js
Normal file
8
components/Main.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
class Main {
|
||||||
|
constructor (send_headers = true) {
|
||||||
|
this.send_headers = send_headers;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = Main;
|
1
components/Method.js
Normal file
1
components/Method.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
// #
|
1
components/Session.js
Normal file
1
components/Session.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
//
|
14
components/types.js
Normal file
14
components/types.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
module.exports = {
|
||||||
|
string : {
|
||||||
|
long_name : 'string',
|
||||||
|
short_name : 'str',
|
||||||
|
syntax : (value, needs_convert = true) => {
|
||||||
|
if (typeof(value) == 'string') {
|
||||||
|
return true, value;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false, needs_convert ? value.toString() : undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user