Skip to content

Commit 35dbc31

Browse files
Add files via upload
1 parent adf2390 commit 35dbc31

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

server.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//Устанавливаем конфигурацию
2+
myConfig = {};
3+
//Конфигурация пользователя (глобальная)
4+
myConfig.data = {
5+
port : 2011,
6+
isDebug : true, //Сообшения сервера
7+
};
8+
//Конфигурация модуля Output
9+
myConfig.output = {
10+
//Папка отображений
11+
dir : require('path').dirname(require.main.filename),
12+
//Очищать код
13+
clear : true,
14+
//Режим отладки
15+
isDebug : false,
16+
};
17+
18+
var output = require('output')(myConfig.output);
19+
//Подключаем нативный модуль http
20+
var http = require('http');
21+
//Формируем задачу
22+
var app = function(req, res) {
23+
if (myConfig.data.isDebug) {
24+
console.log('\nПолучен запрос req.url', req.url);
25+
console.time('app');//Установим метку времени
26+
}
27+
req.output = output;
28+
29+
var rows =
30+
[
31+
{user_id: 11, user_name:'Андрей', user_family:'Иванов', user_active:1},
32+
{user_id: 121, user_name:'Петр', user_family:'Петров', user_active:1},
33+
{user_id: 13, user_name:'Алексей', user_family:'Сидоров', user_active:1},
34+
{user_id: 142, user_name:'Сергей', user_family:'Алексеев', user_active:1},
35+
{user_id: 15, user_name:'Герман', user_family:'Степанов', user_active:0},
36+
];
37+
38+
res.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
39+
/*
40+
res.write(
41+
req.output({
42+
text : 'Hello, World!',
43+
})
44+
);
45+
*/
46+
res.write(
47+
req.output({
48+
//Название файла
49+
file : '/test.php',
50+
//Переменные
51+
data : {
52+
$title : 'Список участников:',
53+
$rows : rows,
54+
width_10: function(str) {
55+
var count = 10;
56+
return (new Array( count ).join(' ') + str).substr(-count).replace(/ /g, ' ');
57+
}
58+
},
59+
})
60+
);
61+
62+
res.end();
63+
64+
if (myConfig.data.isDebug) {
65+
console.timeEnd('app');
66+
}
67+
};
68+
//Создаем сервер для задачи
69+
var server = http.createServer(app);
70+
//Запускаем сервер
71+
server.listen(myConfig.data.port);
72+
//Отображаем информацию о старте сервера
73+
if (myConfig.data.isDebug) console.log('Server start on port ' + myConfig.data.port + ' ...');

test.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml">
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5+
<title>Пример</title>
6+
<style>
7+
body {
8+
font-family:'Lucida Console', Monaco, monospace
9+
}
10+
/*Жирный шрифт*/
11+
.bold {
12+
font-weight:bold
13+
}
14+
/*Серый шрифт*/
15+
.no_active {
16+
color:lightgray;
17+
text-decoration:line-through;
18+
}
19+
</style>
20+
</head>
21+
22+
<body>
23+
<!--Заголовок-->
24+
<div id="title" class="bold"><?='Привет, Мир!'?></div>
25+
<br />
26+
<div><?=$title?></div>
27+
<!--Таблица-->
28+
<div>----------------------------------</div>
29+
<div>|<?=width_10('ID')?>|<?=width_10('ИМЯ')?>|<?=width_10('ФАМИЛИЯ')?>|</div>
30+
<div>----------------------------------</div>
31+
<?php foreach($rows as $key=>$row): ?>
32+
<div class="<?=$row['user_active'] ? '' : 'no_active'?>">|<?=width_10($row['user_id'])?>|<?=width_10($row['user_name'])?>|<?=width_10($row['user_family'])?>|</div>
33+
<?php endforeach; ?>
34+
<div>----------------------------------</div>
35+
</body>
36+
</html>
37+
<script>
38+
/*Комментарий*/
39+
var a1 = 1; //Комментарий
40+
var a2 = 'http://test.ru'; //Комментарий
41+
</script>

0 commit comments

Comments
 (0)