提交 781df704 编写于 作者: M mzabriskie

Updating examples

上级 4ad5438f
......@@ -2,8 +2,8 @@
To run the examples:
1. Clone this repo
2. Run `npm install`
3. Run `grunt build`
4. Run `npm run examples`
5. Open http://localhost:3000
1. `git clone git@github.com:mzabriskie/axios.git`
2. `npm install`
3. `grunt build`
4. `npm run examples`
5. [http://localhost:3000](http://localhost:3000)
......@@ -23,6 +23,31 @@ function listDirs(root) {
return dirs;
}
function getIndexTemplate() {
var links = dirs.map(function (dir) {
var url = '/' + dir;
return '<li onclick="document.location=\'' + url + '\'"><a href="' + url + '">' + url + '</a></li>';
});
return (
'<!doctype html>' +
'<html>' +
'<head>' +
'<title>axios examples</title>' +
'<style>' +
'body {padding:25px;}' +
'ul {margin:0; padding:0; list-style:none;}' +
'li {padding:5px 10px;}' +
'li:hover {background:#eee; cursor:pointer;}' +
'a {text-decoration:none; color:#0080ff;}' +
'</style>' +
'<body>' +
'<ul>' +
links.join('') +
'</ul>'
);
}
function sendResponse(res, statusCode, body) {
res.writeHead(statusCode);
res.write(body);
......@@ -72,10 +97,7 @@ server = http.createServer(function (req, res) {
// Process /
if (url === '/' || url === '/index.html') {
var links = dirs.map(function (dir) {
return '<li><a href="/' + dir + '">' + dir + '</a></li>';
});
send200(res, '<!doctype html><html><body><ul>' + links.join('') + '</ul>');
send200(res, getIndexTemplate());
return;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册