()
| 274 | //--------------------------------------------------------------------- |
| 275 | |
| 276 | export function run() { |
| 277 | // @FIXME: Split these out! |
| 278 | eveSource.add("eve", path.join(config.eveRoot, "examples")); |
| 279 | if(config.internal) { |
| 280 | eveSource.add("root", path.join(config.eveRoot, "examples")); |
| 281 | eveSource.add("examples", path.join(config.eveRoot, "examples")); |
| 282 | } else { |
| 283 | eveSource.add("root", config.root); |
| 284 | } |
| 285 | |
| 286 | |
| 287 | // If a file was passed in, we need to make sure it actually exists |
| 288 | // now instead of waiting for the user to submit a request and then |
| 289 | // blowing up |
| 290 | if(config.path) { |
| 291 | try { |
| 292 | fs.statSync(config.path); |
| 293 | } catch(e) { |
| 294 | throw new Error("Can't load " + config.path); |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | let app = createExpressApp(); |
| 299 | let server = http.createServer(app); |
| 300 | |
| 301 | let WebSocketServer = require('ws').Server; |
| 302 | let wss = new WebSocketServer({server}); |
| 303 | initWebsocket(wss, config.editor); |
| 304 | |
| 305 | server.listen(config.port, function(){ |
| 306 | console.log(`Eve is available at http://localhost:${config.port}. Point your browser there to access the Eve editor.`); |
| 307 | }); |
| 308 | |
| 309 | // If the port is already in use, display an error message |
| 310 | process.on('uncaughtException', function handleAddressInUse(err) { |
| 311 | if(err.errno === 'EADDRINUSE') { |
| 312 | console.log(`ERROR: Eve couldn't start because port ${config.port} is already in use.\n\nYou can select a different port for Eve using the "port" argument.\nFor example:\n\n> eve --port 1234`); |
| 313 | } else { |
| 314 | throw err; |
| 315 | } |
| 316 | process.exit(1); |
| 317 | }); |
| 318 | } |
| 319 | |
| 320 | if(require.main === module) { |
| 321 | console.error("Please run eve using the installed eve binary."); |
no test coverage detected