diff --git a/cornfield/app.js b/cornfield/app.js index e96f66a29..0ed788043 100644 --- a/cornfield/app.js +++ b/cornfield/app.js @@ -10,7 +10,9 @@ const express = require('express'), TEMPLATES_DIR = CONFIG.dirs.templates, PUBLISH_DIR = CONFIG.dirs.publish, PUBLISH_PREFIX = CONFIG.dirs.publishPrefix, - WWW_ROOT = path.resolve(CONFIG.dirs.wwwRoot || __dirname + "/.."); + WWW_ROOT = path.resolve(CONFIG.dirs.wwwRoot || __dirname + "/.."), + VALID_TEMPLATES = CONFIG.templates, + EXPORT_ASSETS = CONFIG.exportAssets; var canStoreData = true; @@ -74,6 +76,7 @@ function publishRoute( req, res ){ } UserModel.findOne( { email: email }, function( err, doc ) { + var i; if ( err ) { res.json({ error: 'internal db error' }, 500); return; @@ -84,20 +87,81 @@ function publishRoute( req, res ){ return; } - for ( var i=0; i<\/script>/g, '' ); + + headEndTagIndex = data.indexOf( '' ); + bodyEndTagIndex = data.indexOf( '' ); + + for ( i = 0; i < EXPORT_ASSETS.length; ++i ) { + externalAssetsString += '\n'; + } - fs.writeFile( projectPath, data, function(){ - if( err ){ - res.json({ error: 'internal file error' }, 500); - return; + popcornString += ''; + + data = data.substring( 0, headEndTagIndex ) + externalAssetsString + data.substring( headEndTagIndex, bodyEndTagIndex ) + popcornString + data.substring( bodyEndTagIndex ); + + fs.writeFile( projectPath, data, function(){ + if( err ){ + res.json({ error: 'internal file error' }, 500); + return; + } + res.json({ error: 'okay', url: url }); + }); + }); } + else { + res.json({ error: 'template not found' }, 500); + return; + } + } + else { + res.json({ error: 'project not found' }, 500); + return; } }); } diff --git a/cornfield/config/default.json b/cornfield/config/default.json index ac78c4092..5a9e83dcc 100644 --- a/cornfield/config/default.json +++ b/cornfield/config/default.json @@ -15,5 +15,17 @@ "templates": "../templates", "publish": "view", "publishPrefix": "http://localhost:8888/cornfield/view" - } + }, + "templates": { + "test": "../templates/test.html", + "robots": "../templates/supported/robots/index.html", + "report": "../templates/supported/report/index.html", + "popup": "../templates/supported/popup/index.html", + "musicvideo": "../templates/supported/musicvideo/index.html", + "context": "../templates/supported/context/index.html", + "robots": "../templates/supported/newscaster/index.html" + }, + "exportAssets": [ + "../../dist/buttered-popcorn.min.js" + ] } diff --git a/templates/test-config.json b/templates/test-config.json index 3c9a2797b..233428fd3 100644 --- a/templates/test-config.json +++ b/templates/test-config.json @@ -1,4 +1,5 @@ { + "name": "test", "savedDataUrl": "saved-data.json", "baseDir": "../" }