使用ruby搭建简易的http服务和sass环境
2015-09-25 15:47
716 查看
使用ruby搭建简易的http服务和sass环境
由于在通常的前端开发情况下,我们会有可能需要一个http服务,当然你可以选择自己写一个node的http服务,也比较简单,比如下面的node代码:var PORT = 3000; var http = require('http'); var url=require('url'); var fs=require('fs'); var mine= { "css": "text/css", "gif": "image/gif", "html": "text/html", "ico": "image/x-icon", "jpeg": "image/jpeg", "jpg": "image/jpeg", "js": "text/javascript", "json": "application/json", "pdf": "application/pdf", "png": "image/png", "svg": "image/svg+xml", "swf": "application/x-shockwave-flash", "tiff": "image/tiff", "txt": "text/plain", "wav": "audio/x-wav", "wma": "audio/x-ms-wma", "wmv": "video/x-ms-wmv", "xml": "text/xml" }; var path=require('path'); var server = http.createServer(function (request, response) { var pathname = url.parse(request.url).pathname; console.log(pathname) var realPath = pathname.substr(1);//path.join("assets", pathname); console.log(realPath); var ext = path.extname(realPath); ext = ext ? ext.slice(1) : 'unknown'; fs.exists(realPath, function (exists) { if (!exists) { response.writeHead(404, { 'Content-Type': 'text/plain' }); response.write("This request URL " + pathname + " was not found on this server."); response.end(); } else { fs.readFile(realPath, "binary", function (err, file) { if (err) { response.writeHead(500, { 'Content-Type': 'text/plain' }); response.end(err); } else { var contentType = mine[ext] || "text/plain"; response.writeHead(200, { 'Content-Type': contentType }); response.write(file, "binary"); response.end(); } }); } }); }); server.listen(PORT); console.log("Server runing at port: " + PORT + ".");
但这个比较麻烦就是每次都要把这个文件copy到项目目录下,而且安装sass环境也是需要ruby的,所以我们有必要了解下gem安装sass 和asdf.
先导官网下载个ruby ,安装完之后就可以使用
gem install sass
命令安装其他组件了,比如要装sass环境.如果要安装beta版本的,可以在命令行中输入
gem install sass --pre
升级命令是
gem update sass
今天我们要装asdf这么个http服务,首先我们使用
gem install asdf
安装完成之后就可以在你需要访问的文件夹目录使用
asdf -p 8080
然后就会出现如下图所示:
然后你就可以使用 http://localhost:8080/ 来访问当前目录的http服务了。
由于国内网络原因,有可能导致 rubygems.org 存放在 Amazon S3 上面的资源文件间歇性连接失败。这时候我们可以通过
gem sources命令来配置源,先移除默认的
https://rubygems.org源,然后添加淘宝的源
https://ruby.taobao.org/,然后查看下当前使用的源是哪个,如果是淘宝的,则表示可以输入sass安装命令
gem install了。
$ gem sources --remove https://rubygems.org/ $ gem sources -a https://ruby.taobao.org/ $ gem sources -l *** CURRENT SOURCES *** https://ruby.taobao.org # 请确保只有 ruby.taobao.org $ gem install sass
相关文章推荐
- httpclient发送request请求时设置header和timeout
- 基于caffenet网络人脸检测模型的测试步骤
- 接口测试HttpClient实践20150925
- Linux内核源代码分析——fork()原理&多进程网络模型 http://blog.csdn.net/hyfcomeon/article/details/9060237
- loadrunner测试TCP协议服务器性能
- 《深入理解Linux网络技术内幕》阅读笔记(二)
- TCP/IP数据报格式分析
- iOS安全系列之二:HTTPS进阶
- 解决DataSnap支持的Tcp长连接数受限的两种方法
- 关于httpclient使用https提交参数
- iOS安全系列之一:HTTPS
- 网络扫描技术揭秘
- 找呀志_java网络编程(5)TCP和udp差额
- 2015北京网络赛 D-The Celebration of Rabbits 动归+FWT
- Xcode7 beta 网络请求报错:The resource could not be loaded because the App Transport Security policy requir
- [原] 利用 OVS 建立 VxLAN 虚拟网络实验
- C# 热敏打印机 Socket 网络链接 打印 图片 (一)
- tcprstat分析服务的响应速度
- DataSnap如何监控Tcp/IP客户端的连接情况
- 第1章 网络基础知识