我下载了.woff
由于中国的某些网络原因,来自 Google 网络字体的文件。之前我尝试过@font-face
那个在Github 页面 http://jiyinyiyong.github.com/she/bin/它有效。但这一次我花了一个小时才找到哪里坏了。
我使用 Node 来提供静态文件mime
,以及content-type
似乎application/x-font-woff
,以及我在 CoffeeScript 中的代码:
exports.read = (url, res) ->
filepath = path.join __dirname, '../', url
if fs.existsSync filepath
file_content = fs.readFileSync filepath, 'utf8'
show (mime.lookup url)
res.writeHead 200, 'content-type': (mime.lookup url)
res.end file_content
else
res.writeHead 404
res.end()
As the content-type
of .woff
在 Github Pages 上是application/octet-stream
,我只是在代码中注释掉该行以使其相同..但它仍然失败:
exports.read = (url, res) ->
filepath = path.join __dirname, '../', url
if fs.existsSync filepath
file_content = fs.readFileSync filepath, 'utf8'
show (mime.lookup url)
# res.writeHead 200, 'content-type': (mime.lookup url)
res.end file_content
else
res.writeHead 404
res.end()
最后,我切换到Nginx服务器来服务.woff
文件..终于开始工作了。
但是如何在 Node 上解决这个问题呢?