最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using Express inside Atom Electron - Stack Overflow

programmeradmin5浏览0评论

I have an application running Express, and I am trying to distribute it using 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/');

When I follow the distribution tutorial (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.

Any ideas?

My only thought is that process.cwd() is not correctly helping me define the document root here:

//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.

I have an application running Express, and I am trying to distribute it using 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/');

When I follow the distribution tutorial (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.

Any ideas?

My only thought is that process.cwd() is not correctly helping me define the document root here:

//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.

Share Improve this question edited Feb 11, 2016 at 22:21 arthurakay asked Apr 24, 2015 at 21:10 arthurakayarthurakay 5,6518 gold badges39 silver badges65 bronze badges 1
  • 1 Can you please provide a working example of electron app that uses mean stack? I would like to learn from that. – Vishal Commented Aug 7, 2016 at 19:56
Add a comment  | 

2 Answers 2

Reset to default 19

It turns out that express for some reason didn't like my document root mapping.

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')));

Don't use process.cwd, use process.resourcesPath instead.

发布评论

评论列表(0)

  1. 暂无评论