gpt4 book ai didi

Node.js 和 Express : "Cannot GET/" static site

转载 作者:太空宇宙 更新时间:2023-11-04 02:28:37 24 4
gpt4 key购买 nike

我正在开发一个小型 Node 应用程序,一切运行良好。它需要从目录 /source 提供一些静态文件。

今天,计算机重新启动后,当我访问本地站点时,我得到的只是 Cannot GET/。自上次运行以来, Node 配置中没有任何变化。

var express = require('express'),
app = express(),
path = require('path'),
fs = require('fs');

// Load our static site to start with
app.use(express.static(path.join(__dirname, 'source')));

// Start the node server
app.listen(3000, function() {
var host = this.address().address,
port = this.address().port;

console.log('Serving Atenium at http://%s:%s', host, port);
});

我的文件夹如下所示:

|- app/
|-- index.js
|- source/
|-- <static files>

关于为什么它停止工作有什么想法吗?

最佳答案

您能否在此过程中更新您的 Express 模块?我相信在 Express 4 中,静态内容现在由此处的serve-static 中间件库处理 https://github.com/expressjs/serve-static .

关于Node.js 和 Express : "Cannot GET/" static site,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28680429/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com