Skip to content

Instantly share code, notes, and snippets.

@faddah
Last active August 29, 2015 14:24
Show Gist options
  • Select an option

  • Save faddah/3ff4dde3d355434b95e2 to your computer and use it in GitHub Desktop.

Select an option

Save faddah/3ff4dde3d355434b95e2 to your computer and use it in GitHub Desktop.
trying to serve a bootstrap html/css file, works as just "file:///..." in browser, doesn't work served by node.js
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE-edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap Example</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="style.css">
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
</head>
<body>
<div id="answer"></div>
<div>
<button class="btn btn-success">Absolute, Total Success Button!</button>
</div>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="jq_example.js"></script>
</body>
</html>
var http = require('http'),
fs = require('fs'),
path = require('path')
express = require('express'),
app = express();
console.log(path.resolve('./bootstrap_example.html'));
/*
fs.readFile('./bootstrap_example.html', function (err, html) {
if (err) {
throw err;
}
http.createServer(function(request, response) {
response.writeHeader(200, {"Content-Type": "text/html"});
response.write(html);
response.end();
}).listen(3000);
console.log('The Bootstrap Server is now alive & running on Localhost Port 3000 - have fun!')
});
*/
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname + '/bootstrap_example.html'));
});
app.listen(3000, function(err) {
if(err) {
throw err;
}
console.log('The Bootstrap Server is now alive & running on Localhost Port 3000 - have fun!')
});
$( document ).ready(function() {
alert( "Ready!" );
$("#answer").html("<h2><em>\n\t\tYeah, jQuery b aaawwll up in dis Bad Boy!</em></h2>\n\n");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment