Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Host out of www directory #2

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/

# project specifics
build.js
config.json
www/
8 changes: 6 additions & 2 deletions config.json.default
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
"port": "3000",
"sslKey": "/path/to/privkey.pem",
"sslCert": "/path/to/cert.pem",

"proxyPath": "/proxy",
"rootPath": ".",
"rootPath": "www/",
"basePath": "",

"annotationPath": "annotation/",
"inboxPath": "inbox/",
"queuePath": "queue/",
"annotationPath": "annotation/",
"reportsPath": "reports/",

"maxPayloadSize": 10000,
"maxResourceCount": 10,
"maxMemberCount": 10
Expand Down
34 changes: 30 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ function getConfigFile(configFile){
return config;
}

function createDir(path) {
if (!fs.existsSync(path)) {
fs.mkdirSync(path);
}
}

function config(configFile){
var config = getConfigFile(configFile);

Expand All @@ -186,19 +192,38 @@ function config(configFile){
config['port'] = config.port || 3000;
config['scheme'] = (config.sslKey && config.sslCert) ? 'https' : 'http';
config['authority'] = config.scheme + '://' + config.hostname + ':' + config.port;
config['rootPath'] = config.rootPath || ((process.cwd() != __dirname) ? process.cwd() : '.');
config['rootPath'] = config.rootPath || ((process.cwd() != __dirname) ? process.cwd() + '/www/' : 'www/');
config['basePath'] = config.basePath || '';

// pre-provided resource endpoints
config['annotationPath'] = config.annotationPath || 'annotation/';
config['inboxPath'] = config.inboxPath || 'inbox/';
config['queuePath'] = config.queuePath || 'queue/';
config['annotationPath'] = config.annotationPath || 'annotation/';
config['reportsPath'] = config.reportsPath || 'reports/';

config['maxPayloadSize'] = config.maxPayloadSize || 100000;
config['maxResourceCount'] = config.maxResourceCount || 100;
config['maxMemberCount'] = config.maxMemberCount || 10;
config['proxyPath'] = config.proxyPath || '/proxy';

var createDirectories = [config['inboxPath'], config['queuePath'], config['annotationPath'], config['reportsPath']];
createDirectories.forEach(function(path){ if(!fs.existsSync(path)){ fs.mkdirSync(path); } });
// create the `rootPath` directory
createDir(config['rootPath']);
// ...all others are relative to `rootPath`
var createThese = [
config['annotationPath'], config['inboxPath'], config['queuePath'],
config['reportsPath']
];
createThese.forEach(function(path) {
createDir(config['rootPath'] + path);
});

// rootPath folder does not contain an index.html file...so we'll copy the
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we ship with www/index.html and avoid this altogether? It is possible that the server may not want to have an index.html and so this shouldn't override that I think.

// default one in.
if (!fs.existsSync(config.rootPath + 'index.html')
&& fs.existsSync(process.cwd() + '/index.html')) {
fs.createReadStream(process.cwd() + '/index.html')
.pipe(fs.createWriteStream(config.rootPath + 'index.html'));
}

//console.log(config);
return config;
Expand Down Expand Up @@ -304,6 +329,7 @@ console.log(config);

app.use(function(req, res, next) {
// module.exports.accept = accept = accepts(req);

req.requestedType = req.accepts(acceptRDFTypes);
// console.log(req.requestedType);
req.requestedType = (req.requestedType) ? req.requestedType.split(';')[0].trim() : req.requestedType;
Expand Down