javascript 在 Atom Electron 中使用 Express
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29857555/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using Express inside Atom Electron
提问by arthurakay
I have an application running Express, and I am trying to distribute it using electron.
我有一个运行 Express 的应用程序,我正在尝试使用electron分发它。
Running electron in debug with this:
在调试中运行电子:
/path/to/electron/Electron.app/Contents/MacOS/Electron path-to-my-app
My application runs perfectly fine. Express fires up its server and everything works -- the main window opens correctly using mainWindow.loadUrl('http://localhost:3000/');
我的应用程序运行得很好。Express 启动它的服务器并且一切正常——主窗口使用正确打开mainWindow.loadUrl('http://localhost:3000/');
When I follow the distributiontutorial (linked before) I copy my application resources to:
当我遵循分发教程(之前链接)时,我将我的应用程序资源复制到:
/path/to/electron/Electron.app/Contents/Resources/app
But now when I run Electron.app, I see Cannot GET /
in the main window... but I have no idea why.
但是现在当我运行 Electron.app 时,我Cannot GET /
在主窗口中看到......但我不知道为什么。
Any ideas?
有任何想法吗?
My only thought is that process.cwd()
is not correctly helping me define the document root here:
我唯一的想法是process.cwd()
不能正确帮助我在这里定义文档根目录:
//configure Express to default web requests to /workspace/ folder
expressApp.use(express.static(process.cwd() + '/workspace'));
But if that's the case, I don't know how to get around it.
但如果是这样的话,我不知道如何解决它。
回答by arthurakay
It turns out that express
for some reason didn't like my document root mapping.
事实证明,express
由于某种原因不喜欢我的文档根映射。
Rather than using:
而不是使用:
//configure Express to default web requests to /workspace/ folder
expressApp.use(express.static(process.cwd() + '/workspace'));
I instead use this:
我改为使用这个:
expressApp.use(express.static(path.join(__dirname, 'workspace')));
回答by Ana Betts
Don't use process.cwd
, use process.resourcesPath
instead.
不要使用process.cwd
,process.resourcesPath
而是使用。