Permalink
Browse files

server fix

  • Loading branch information...
Zertuk committed Feb 1, 2016
1 parent 396cdb8 commit 5bb385da46b8e80fe2ac9f1066791fa758a7a207
View
@@ -0,0 +1,83 @@
//This is needed in order to test 404.html, router.js, and api.html
//NPM-Free Server by The Jared Wilcurt
//All you need to run this is an installed copy of Node.JS
//Require in some of the native stuff that comes with Node
var http = require("http");
var url = require("url");
var path = require("path");
var fs = require("fs");
//Port number to use
var port = process.argv[2] || 8000;
//Colors for CLI output
var WHT = "\033[39m";
var RED = "\033[91m";
var GRN = "\033[32m";
//Create the server
http.createServer(function (request, response) {
//The requested URL like http://localhost:8000/file.html
var uri = url.parse(request.url).pathname;
//get the file.html from above and then find it from the current folder
var filename = path.join(process.cwd(), uri);
//Setting up MIME-Types
var contentTypesByExtension = {
'.html': "text/html",
'.css': "text/css",
'.js': "text/javascript",
".json": "text/json"
};
//Check if the requested file exists
fs.exists(filename, function(exists) {
//If it doesn't
if (!exists) {
//Output a red error pointing to failed request
console.log(RED + "FAIL: " + filename);
//Redirect the browser to the 404 page
filename = path.join(process.cwd(), '/404.html');
//If the requested URL is a folder, like http://localhost:8000/catpics
} else if (fs.statSync(filename).isDirectory()) {
//Output a green line to the console explaining what folder was requested
console.log(GRN + "FLDR: " + WHT + filename);
//redirect the user to the index.html in the requested folder
filename += 'index.html';
}
//Assuming the file exists, read it
fs.readFile(filename, "binary", function(err, file) {
//Output a green line to console explaining the file that will be loaded in the browser
console.log(GRN + "FILE: " + WHT + filename);
//If there was an error trying to read the file
if (err) {
//Put the error in the browser
response.writeHead(500, {"Content-Type": "text/plain"});
response.write(err + "\n");
response.end();
return;
}
//Otherwise, declar a headers object and a var for the MIME-Type
var headers = {};
var contentType = contentTypesByExtension[path.extname(filename)];
//If the requested file has a matching MIME-Type
if (contentType) {
//Set it in the headers
headers["Content-Type"] = contentType;
}
//Output the read file to the browser for it to load
response.writeHead(200, headers);
response.write(file, "binary");
response.end();
});
});
}).listen(parseInt(port, 10));
//Message to display when server is started
console.log(WHT + "Static file server running at\n => http://localhost:" + port + "/\nCTRL + C to shutdown");
View
@@ -20,6 +20,9 @@
background: @color_white;
color: @color_black;
}
#__bs_notify__ {
display: none !important;
}
* {
/*-webkit-box-shadow: none !important;
View
@@ -14,8 +14,8 @@
<link rel="stylesheet" href="styles/lib-9de3c31031.css">
<link href='http://fonts.googleapis.com/css?family=Inconsolata' rel='stylesheet' type='text/css'>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
<link rel="stylesheet" href="styles/app-0b9b81a034.css">
<link rel="shortcut icon" href="/images/favicon.ico" type="image/x-icon"/>
<link rel="stylesheet" href="styles/app-7b548f7358.css">
</head>
<body>
<div ng-controller = "MainController as vm" ng-cloak ng-hide = "!vm.player">
@@ -58,7 +58,7 @@
<script src="https://cdn.firebase.com/js/client/2.4.0/firebase.js"></script>
<script src="js/lib-bc8ca47d70.js"></script>
<script src="js/app-af98a0e57d.js"></script>
<script src="js/app-a81874f043.js"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
View

Large diffs are not rendered by default.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -11,9 +11,13 @@
"dependencies": {
"angular-tooltips": "^0.1.25",
"body-parser": "^1.8.2",
"compression": "^1.6.1",
"connect": "^3.4.1",
"express": "^4.9.3",
"http": "0.0.0",
"morgan": "^1.1.1",
"serve-favicon": "^2.0.1"
"serve-favicon": "^2.0.1",
"serve-static": "^1.10.2"
},
"devDependencies": {
"browser-sync": "^2.7.13",
Oops, something went wrong.

0 comments on commit 5bb385d

Please sign in to comment.