Express无法加载索引

时间:2018-04-25 23:02:34

标签: node.js amazon-web-services express

我正在尝试在aws上设置我的第一个快速Web服务器。如果我尝试简单地使用“res.send”,我可以在9000端口显示hello world,但是我的下面的代码会产生错误,我相信它与我的目录结构有关,但我似乎无法找到正确的写它的方式。我的server.js文件位于名为home / server / server.js的文件夹中,但是我尝试加载的索引文件位于home / web / index.html中。我怎么写这个,所以它正确加载。这是我的代码:

ForbiddenError: Forbidden
    at SendStream.error (/home/ubuntu/home/node_modules/send/index.js:270:31)
    at SendStream.pipe (/home/ubuntu/home/node_modules/send/index.js:554:12)
    at sendfile (/home/ubuntu/home/node_modules/express/lib/response.js:1099:8)
    at ServerResponse.res.sendfile (/home/ubuntu/home/node_modules/express/lib/response.js:498:3)
    at ServerResponse.eval [as sendfile] (eval at wrapfunction (/home/ubuntu/home/node_modules/depd/index.js:410:22), <anonymous>:4:11)
    at /home/ubuntu/home/server/server.js:30:9
    at Layer.handle [as handle_request] (/home/ubuntu/home/node_modules/express/lib/router/layer.js:95:5)
    at next (/home/ubuntu/home/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/home/ubuntu/home/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/home/ubuntu/home/node_modules/express/lib/router/layer.js:95:5)

这是我目前得到的错误:

# convert the pointer to a buffer. 
buffer = c_char * length 
messageToSend = buffer.from_address(message)

感谢您的帮助!

1 个答案:

答案 0 :(得分:3)

  

path必须是绝对路径或指定root到res.sendFile

您可以使用root选项:

res.sendFile('index.html', { root: '.' })

顺便说一下,sendfile已弃用,请使用sendFile

相关问题