Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixed trailing slash URL bug and relative path issues #42

Merged
merged 3 commits into from

2 participants

@hillct

These changes correct an issue where if an API is selected using a URL with a trailing slash, the target API JSON file can not be found. The fix is to strip off any trailing slash when such a route is used.

These changes also correct problematic relative paths described in issue #25 preventing use of standard System V style init scripts to start and stop iodocs.

@mansilladev mansilladev merged commit c67a665 into mashery:master
@phairow phairow referenced this pull request
Closed

Node.js init script #25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 3 deletions.
  1. +4 −3 app.js
View
7 app.js
@@ -70,7 +70,7 @@ db.on("error", function(err) {
// Load API Configs
//
var apisConfig;
-fs.readFile('public/data/apiconfig.json', 'utf-8', function(err, data) {
+fs.readFile(__dirname +'/public/data/apiconfig.json', 'utf-8', function(err, data) {
if (err) throw err;
apisConfig = JSON.parse(data);
if (config.debug) {
@@ -620,7 +620,7 @@ app.dynamicHelpers({
if (!req.params.api) {
pathName = req.url.replace('/','');
// Is it a valid API - if there's a config file we can assume so
- fs.stat('public/data/' + pathName + '.json', function (error, stats) {
+ fs.stat(__dirname + '/public/data/' + pathName + '.json', function (error, stats) {
if (stats) {
req.params.api = pathName;
}
@@ -647,7 +647,7 @@ app.dynamicHelpers({
},
apiDefinition: function(req, res) {
if (req.params.api) {
- var data = fs.readFileSync('public/data/' + req.params.api + '.json');
+ var data = fs.readFileSync(__dirname + '/public/data/' + req.params.api + '.json');
return JSON.parse(data);
}
}
@@ -692,6 +692,7 @@ app.post('/upload', function(req, res) {
// API shortname, all lowercase
app.get('/:api([^\.]+)', function(req, res) {
+ req.params.api=req.params.api.replace(/\/$/,'');
res.render('api');
});
Something went wrong with that request. Please try again.