Commit f291eccb authored by Compilenix's avatar Compilenix

Move multiused libraries/var's/functions to a global scope

parent 78af5967
......@@ -6,6 +6,10 @@ Fonts["Regular_path"] = fonts.Regular_path;
Fonts["Bold"] = fonts.Bold;
Fonts["Regular_path"] = fonts.Regular_path;
replaceAll = function (find, replace, str) {
return str.replace(new RegExp(find.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'), replace);
};
exports.Index = require('./requestHandlers/Index.js').Index;
exports.Post = require('./requestHandlers/Post.js').Post;
exports.Favicon = require('./requestHandlers/Favicon.js').Favicon;
......
var fs = require('fs');
function Favicon(request, response) {
_writeHead["_200"](response, { "Content-Type": "image/x-icon", "Server": "node.js/" + process.version });
fs.readFile('favicon.ico', function (error, data) {
_fs.readFile('favicon.ico', function (error, data) {
if (error) {
//console.log(error);
}
......
var fs = require('fs');
var version = "0.80";
var Regular_path = 'cdn/fonts/ubuntu-font-family-' + version + '/Ubuntu-R.ttf';
......@@ -7,7 +6,7 @@ var Bold_path = 'cdn/fonts/ubuntu-font-family-' + version + '/Ubuntu-B.ttf';
function Regular(request, response) {
_writeHead["_200"](response, { "Content-Type": "application/octet-stream", "Server": "node.js/" + process.version });
fs.readFile(Regular_path, function (error, data) {
_fs.readFile(Regular_path, function (error, data) {
if (error) {
//console.log(error);
}
......@@ -18,7 +17,7 @@ function Regular(request, response) {
function Bold(request, response) {
_writeHead["_200"](response, { "Content-Type": "application/octet-stream", "Server": "node.js/" + process.version });
fs.readFile(Bold_path, function (error, data) {
_fs.readFile(Bold_path, function (error, data) {
if (error) {
//console.log(error);
}
......
var fs = require('fs');
var querystring = require('querystring');
var url = require('url');
var Options = {
FileHeader: "header.html",
......@@ -14,7 +11,7 @@ var Options = {
function Index(request, response) {
_writeHead["_200"](response);
fs.readFile(Options.FileHeader, 'utf8', function (error, data) {
_fs.readFile(Options.FileHeader, 'utf8', function (error, data) {
index(error, data, request, response);
});
}
......@@ -25,9 +22,9 @@ function index(error, data, request, response) {
}
response.write(data);
var posts = fs.readdirSync(Options.DirectoryPosts).reverse();
var posts = _fs.readdirSync(Options.DirectoryPosts).reverse();
var counter = 0;
var queryOffset = offset = parseInt(querystring.parse(url.parse(request.url).query)["offset"], 10);
var queryOffset = offset = parseInt(_querystring.parse(_url.parse(request.url).query)["offset"], 10);
var foundSomeThing = false;
var printEndMessage = false;
......@@ -41,14 +38,14 @@ function index(error, data, request, response) {
if (counter < Options.CountPosts) {
if (fs.existsSync(Options.DirectoryPosts + '/' + posts[i] + ".asc")) {
if (_fs.existsSync(Options.DirectoryPosts + '/' + posts[i] + ".asc")) {
if (queryOffset > 0) {
queryOffset--;
} else {
response.write('<li>');
response.write('[<a href="post/?p=' + posts[i].replace(".html", '') + '">post</a>] ');
response.write(replaceAll('\n', '', fs.readFileSync(Options.DirectoryPosts + '/' + posts[i], 'utf8')));
response.write(replaceAll('\n', '', _fs.readFileSync(Options.DirectoryPosts + '/' + posts[i], 'utf8')));
response.write('</li>\n');
counter++;
foundSomeThing = true;
......@@ -103,9 +100,5 @@ function index(error, data, request, response) {
response.end();
}
function replaceAll(find, replace, str) {
return str.replace(new RegExp(find.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'), replace);
}
exports.Index = Index;
var url = require('url');

function Route(handle, request, response) {
var pathname = url.parse(request.url).pathname;
var pathname = _url.parse(request.url).pathname;
if (typeof handle[pathname] === 'function') {
handle[pathname](request, response);
......
var http = require('http');
_http = require('http');
_url = require('url');
_querystring = require('querystring');
_fs = require('fs');
_writeHead = require('./writeHead.js');
var Options = {
......@@ -12,7 +14,7 @@ function Start(handle, route) {
process_request(request, response, handle, route);
}
http.createServer(onRequest).listen(Options.Port);
_http.createServer(onRequest).listen(Options.Port);
console.log("Server has started and listening on port: " + Options.Port);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment