我正在尝试学习如何使用node.js,并且我已经开始使用this tutorial了。当我直接用node app.js
启动节点时,一切正常。当我使用pm2 start app.js
在PM2下运行节点作为服务时,一切也正常。
但是,如果我在使用pm2 start app.js --watch
更改文件时尝试让PM2自动重启我的节点应用程序,它会停止正确提供我的CSS,并且 ERR_EMPTY_RESPONSE 在Chrome中尝试查看CSS文件的路径时。
PM2错误日志为空。输出日志仅记录网站根目录的GET请求,并带有304响应代码。如果我直接使用节点,则控制台会为根记录200响应,对第一页加载的style.css执行200响应,对同一个nod会话的每个后续页面加载执行304响应。
我已尝试使用processes.json
中详细说明使用// ./app.js
var express = require('express'),
stylus = require('stylus),
nib = require('nib'),
app = express();
function compile(str, path) {
return stylus(str).set('filename', path).use(nib());
}
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.logger('dev'));
app.use(stylus.middleware({ src: __dirname + '/public', compile: compile }));
app.use(express.static(__dirname + '/public'));
app.get('/', function(req, res) {
res.render('index', { title: 'My Title' });
});
app.listen(3000);
准确指定要使用PM2观看哪些文件,但它似乎不会影响结果。
//- ./views/layout.jade
doctype
html
head
title #{title}
link(rel='stylesheet', href='/stylesheets/style.css')
body
header
h1 #{title}
.container
.main-content
block content
.sidebar
block sidebar
footer
p Running on node with Express, Jade, and Stylus
/* ./public/stylesheets/style.styl */
@import 'nib'
@import url('http://fonts.googleapis.com/css?family=Quicksand')
global-reset()
main-color = #fa5b4d
background-color = #faf9f0
body
font-family 'Georgia'
background-color background-color
color #444
header
font-family 'Quicksand'
padding 50px 10px
color #fff
font-size 25px
text-align center
background-color main-color
border-bottom 1px solid darken(main-color, 30%)
text-shadow 0px -1px 0px darken(main-color, 30%)
.container
width 500px
margin 50px auto
overflow hidden
.main-content
float left
width 300px
p
margin-bottom 20px
.sidebar
float left
width 200px
.widget
border-radius 3px
border 1px solid #ccc
margin-left 20px
background-color background-color
box-shadow inset 0px 0px 0px 3px rgba(#fff, 0.8), 0px 3px 0px -2px rgba(#000, 0.1)
h1
font-family 'Quicksand'
margin 13px 10px 4px
padding-bottom 10px
border-bottom 1px dotted #ddd
border-radius 2px 2px 0px 0px
margin-bottom 10px
p
font-size 13px
padding 0px 10px
margin-bottom 10px
p
line-height 1.0
footer
width 500px
margin 50px auto
border-top 1px dotted #ccc
padding-top 5px
font-size 13px
<!-- generated html (whitespace added for readability) -->
<!DOCTYPE html>
<html>
<head>
<title>My Title</title>
<link rel="stylesheet" href="/stylesheets/style.css">
</head>
<body>
<header><h1>My Title</h1></header>
<div class="container">
<div class="main-content">
<p>Vivamus hendrerit arcu sed erat molestie
vehicula. Sed auctor neque eu tellus
rhoncus ut eleifend nibh porttitor. Ut in.</p>
<p>Donnec congue lacinia dui, a porttitor
lectus condimentum laoreet. Nunc eu
ullamcorper orci. Quisque eget odio ac
lectus vestibulum faucibus eget in metus.
In pellentesque faucibus vestibulum. Nulla
at nulla justo, eget luctus tortor.</p>
</div>
<div class="sidebar">
<div class="widget">
<h1>Widget</h1>
<p>Sed auctor neque eu tellus rhoncus ut
eleifend nibh porttitor. Ut in nulla enim.</p>
<p>Vivamus hendrerit arcu sed erat molestie
vehicula.</p>
</div>
</div>
</div>
<footer>
<p>Running on node with Express, Jade and Stylus</p>
</footer>
</body>
</html>
{
"@context": {
"@vocab": "http://schema.org/"
}
}