Matteo Scandolo | cf06077 | 2016-05-13 15:54:44 -0700 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
Matteo Scandolo | cf06077 | 2016-05-13 15:54:44 -0700 | [diff] [blame] | 3 | var path = require('path'); |
Matteo Scandolo | c9306e4 | 2016-08-04 16:24:30 -0700 | [diff] [blame] | 4 | var express = require('express'); |
| 5 | var app = express(); |
Matteo Scandolo | cf06077 | 2016-05-13 15:54:44 -0700 | [diff] [blame] | 6 | |
| 7 | var conf = { |
| 8 | paths: { |
| 9 | root: '../../../../../' |
| 10 | }, |
| 11 | port: '8182' |
| 12 | } |
| 13 | |
Matteo Scandolo | c9306e4 | 2016-08-04 16:24:30 -0700 | [diff] [blame] | 14 | if (process.env.ONOS_EXTERNAL_APP_DIRS) { |
| 15 | var external_apps = process.env.ONOS_EXTERNAL_APP_DIRS.replace(/\s/,'').split(','); |
| 16 | external_apps.forEach(function(a, i){ |
| 17 | let [appName, appPath] = a.split(':'); |
| 18 | conf.paths[appName] = appPath; |
| 19 | }); |
| 20 | } |
Matteo Scandolo | cf06077 | 2016-05-13 15:54:44 -0700 | [diff] [blame] | 21 | |
Matteo Scandolo | c9306e4 | 2016-08-04 16:24:30 -0700 | [diff] [blame] | 22 | var httpProxyInit = function (baseDirs) { |
Matteo Scandolo | cf06077 | 2016-05-13 15:54:44 -0700 | [diff] [blame] | 23 | |
Matteo Scandolo | c9306e4 | 2016-08-04 16:24:30 -0700 | [diff] [blame] | 24 | Object.keys(baseDirs).forEach(dir => { |
| 25 | var d = path.isAbsolute(baseDirs[dir]) ? baseDirs[dir] : path.join(__dirname, baseDirs[dir]); |
| 26 | app.use(express.static(d)); |
| 27 | }); |
Matteo Scandolo | cf06077 | 2016-05-13 15:54:44 -0700 | [diff] [blame] | 28 | |
Matteo Scandolo | c9306e4 | 2016-08-04 16:24:30 -0700 | [diff] [blame] | 29 | app.get('/', function (req, res) { |
| 30 | res.send('Hello World!'); |
| 31 | }); |
Matteo Scandolo | cf06077 | 2016-05-13 15:54:44 -0700 | [diff] [blame] | 32 | |
Matteo Scandolo | c9306e4 | 2016-08-04 16:24:30 -0700 | [diff] [blame] | 33 | app.listen(conf.port, function () { |
| 34 | console.log(`Dev server is up and listening on http://localhost:${conf.port}!`); |
Matteo Scandolo | cf06077 | 2016-05-13 15:54:44 -0700 | [diff] [blame] | 35 | }); |
| 36 | }; |
| 37 | |
Matteo Scandolo | c9306e4 | 2016-08-04 16:24:30 -0700 | [diff] [blame] | 38 | httpProxyInit(conf.paths); |
| 39 | |
| 40 | |
| 41 | |