Skip to content

Commit

Permalink
Small improvements to docularserver:
Browse files Browse the repository at this point in the history
1.  use sendFile instead of sendfile to avoid deprecation error
2. Send site.json and structure.json via sendFile and not express static to avoid issues with different OS's (windows).
3. return 404 on files that are not found inside the resource folders to ease debugging
4. fallback to docular grunt config to try and figure out the target folder
5. throw an error if not target folder found that explains what needs to be fixed
  • Loading branch information
Idan Bauer committed Dec 18, 2014
1 parent 0467ad1 commit 8da8495
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions tasks/docular.js
Expand Up @@ -92,9 +92,12 @@ module.exports = function(grunt) {

var path=require('path');

var options = grunt.config('docularserver') || {};
var options = grunt.config('docularserver') || grunt.config('docular');
var port = requestedPort || options.port || 8000;
var targetDir = path.join(process.cwd(), options.targetDir)
var targetDir = path.join(process.cwd(), options.targetDir || options.docular_webapp_target);
if (targetDir === process.cwd()){
console.warn('you need to supply either docular.docular_webapp_target or docularserver.targetDir to use this server'.yellow);
}

//Grab a new async promise
var process_server_done = this.async();
Expand All @@ -114,15 +117,22 @@ module.exports = function(grunt) {
app.use('/documentation', express.static(path.join(targetDir, '/documentation')));
app.use('/sources', express.static(path.join(targetDir, '/sources')));
app.use('/resources', express.static(path.join(targetDir, '/resources')));
app.use('/site.json', express.static(path.join(targetDir, '/site.json')));
app.use('/structure.json', express.static(path.join(targetDir, '/structure.json')));

app.use('/resources', function(req,res){
res.status(404).send('');
app.use(['/resources', '/configs', '/controller', '/documentation', '/sources'] , function(req,res){
res.status(404).send('file not found');
});

app.use('/site.json', function(req, res){
res.sendFile(path.join(targetDir, '/site.json'));
});

app.use('/structure.json', function(req, res){
res.sendFile(path.join(targetDir, '/structure.json'));
});


app.use('/', function (req, res){
res.sendfile(path.join(targetDir, '/index.html'));
res.sendFile(path.join(targetDir, '/index.html'));
});

var server = app.listen(port, function(){
Expand Down

0 comments on commit 8da8495

Please sign in to comment.