-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #868 from OpenGeoscience/express-serve
Refactor the server script to serve dist, website, and _build.
- Loading branch information
Showing
8 changed files
with
97 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* global require, module */ | ||
'use strict'; | ||
|
||
var serveIndex; | ||
try { | ||
serveIndex = require('serve-index'); | ||
} catch (err) { } | ||
var express = require('express'), | ||
app = express(), | ||
help = false, | ||
skip = 2, | ||
port = 30100, | ||
build = false, | ||
dist = false, | ||
website = false; | ||
|
||
process.argv.forEach(function (val, idx) { | ||
if (skip) { | ||
skip -= 1; | ||
return; | ||
} | ||
if (val === '--build' || val === '-b') { | ||
build = true; | ||
} else if (val === '--dist' || val === '-d') { | ||
dist = true; | ||
} else if ((val === '--port' || val === '-p') && idx + 1 < process.argv.length) { | ||
port = parseInt(process.argv[idx + 1], 10); | ||
skip = 1; | ||
} else if (val.substr(0, 7) === '--port=') { | ||
port = parseInt(val.substr(7), 10); | ||
} else if (val === '--website' || val === '--web' || val === '-w') { | ||
website = true; | ||
} else { | ||
help = true; | ||
} | ||
}); | ||
|
||
if (help) { | ||
console.error('Serve the dist, website, and _build directories. Options:\n' + | ||
'--build : serve _build directory as build/\n' + | ||
'--dist : serve distribution directory (default)\n' + | ||
'--port (port) : default 30100\n' + | ||
'--website : serve website directory (if this and dist are specified,\n' + | ||
' dist is located as dist/)\n'); | ||
process.exit(1); | ||
} | ||
|
||
if (!website) { | ||
if (!build || dist) { | ||
app.use(express.static('dist')); | ||
} | ||
} else { | ||
if (dist) { | ||
app.use('/dist', express.static('dist')); | ||
} | ||
app.use(express.static('website/public')); | ||
} | ||
if (build) { | ||
if (serveIndex) { | ||
app.use('/build', express.static('_build'), serveIndex('_build', {icons: true, view: 'details'})); | ||
} else { | ||
app.use('/build', express.static('_build')); | ||
} | ||
} | ||
|
||
app.listen(port, function () { | ||
console.log('Server listening on ' + port); | ||
}); | ||
|
||
module.exports = app; |