diff --git a/category.js b/category.js new file mode 100644 index 0000000..e69de29 diff --git a/includes.js b/includes.js new file mode 100644 index 0000000..e3ecf43 --- /dev/null +++ b/includes.js @@ -0,0 +1,25 @@ +/** + Includes.js + File used for getting the header and footer + */ +const utils = require('./utils.js'); + +const HEADER_FILE = "includes/header.html"; + +const FOOTER_FILE = "includes/footer.html"; + +module.exports = +{ + printHeader: function(res) + { + res.writeHead(200, {'Content-Type': 'text/html'}); + utils.include(res, HEADER_FILE); + //res.write("Header
"); + }, + printFooter: function(res) + { + //res.write("footer"); + utils.include(res, FOOTER_FILE); + res.end(); + } +}; \ No newline at end of file diff --git a/server.js b/server.js new file mode 100644 index 0000000..dd5410a --- /dev/null +++ b/server.js @@ -0,0 +1,35 @@ +var http = require('http'); +const url = require('url'); +const fs = require('fs'); +const utils = require('./utils.js'); +const includes = require('./includes.js'); + +http.createServer(function (req, res) +{ + var q = url.parse(req.url, true); + var filename = "." + q.pathname; + + //prints header + includes.printHeader(res); + + utils.include(res, "README.md"); + + if(filename.includes("/category")) + { + console.log("categories"); + test(); + } + else if(filename.includes("/posts/")) + { + console.log("posts"); + } + else if(filename.includes("/downloads/")) + { + console.log("downloads"); + } + else + { + console.log("default"); + } + includes.printFooter(res); +}).listen(8080); \ No newline at end of file diff --git a/utils.js b/utils.js new file mode 100644 index 0000000..47961c1 --- /dev/null +++ b/utils.js @@ -0,0 +1,14 @@ +/** + Utilities is a node modules created to make tasks like + including html files easier for me programming. + */ + +const fs = require('fs'); + +module.exports= +{ + include: function(res, fileName) + { + res.write(fs.readFileSync(fileName)); + } +}; \ No newline at end of file