Express.js仅在生产服务器

时间:2018-01-22 11:53:21

标签: node.js express http-headers mime-types helmet.js

计算机上的本地(Mac)(开发环境)当我向静态请求curl时,所有工作正常,服务器响应为200,但如果我在服务器上运行相同的代码,并请求静态响应为404,对于所有其他静态图像,html文件表示响应200.

var express = require("express");
var path = require("path");
var logger = require("morgan");
var cookieParser = require("cookie-parser");
var bodyParser = require("body-parser");
var sassMiddleware = require("node-sass-middleware");
var helmet = require("helmet");

var app = express();

app.use(logger("dev"));
app.use(helmet());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(sassMiddleware({
    src: path.join(__dirname, "public"),
    dest: path.join(__dirname, "public"),
    indentedSyntax: false, // true = .sass and false = .scss
    outputStyle: "compressed",
    force: true,
    sourceMap: false
}));

app.disable("x-powered-by");

app.use(express.static(path.join(__dirname, "public")));

app.get("/", function (req, res) {
    res.sendFile(path.join(__dirname, "public/index.html"));
});


module.exports = app;

项目树

   - app
    |- public
       |- assets (js files here)
       |- images
       |- stylesheets
       |- index.html
    |- node_modules
    |- bin
       | - www
    |- app.js
    |- package.json
    |- .gitignore

/路线

的响应实例
HTTP/1.1 200 OK
X-DNS-Prefetch-Control: off
X-Frame-Options: SAMEORIGIN
Strict-Transport-Security: max-age=15552000; includeSubDomains
X-Download-Options: noopen
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Accept-Ranges: bytes
Cache-Control: public, max-age=0
Last-Modified: Mon, 22 Jan 2018 11:02:05 GMT
ETag: W/"1ac9-1611d8844f1"
Content-Type: text/html; charset=UTF-8
Content-Length: 6857
Vary: Accept-Encoding
Date: Mon, 22 Jan 2018 11:45:09 GMT
Connection: keep-alive

/images/logo.png路线

的响应实例
HTTP/1.1 200 OK
X-DNS-Prefetch-Control: off
X-Frame-Options: SAMEORIGIN
Strict-Transport-Security: max-age=15552000; includeSubDomains
X-Download-Options: noopen
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Accept-Ranges: bytes
Cache-Control: public, max-age=0
Last-Modified: Mon, 22 Jan 2018 06:25:07 GMT
ETag: W/"749-1611c8ab42f"
Content-Type: image/png
Content-Length: 1865
Date: Mon, 22 Jan 2018 11:46:18 GMT
Connection: keep-alive

返回404 Not Found的/assets/jquery/dist/jquery.min.js路由的响应实例

HTTP/1.1 404 Not Found
X-DNS-Prefetch-Control: off
X-Frame-Options: SAMEORIGIN
Strict-Transport-Security: max-age=15552000; includeSubDomains
X-Download-Options: noopen
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Content-Security-Policy: default-src 'self'
Content-Type: text/html; charset=utf-8
Content-Length: 172
Vary: Accept-Encoding
Date: Mon, 22 Jan 2018 11:47:20 GMT
Connection: keep-alive

0 个答案:

没有答案