Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ty#176: minor changes to proxying to smoothen things a bit
  • Loading branch information
grtjn committed Sep 16, 2015
1 parent aab0e98 commit b36f66b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
8 changes: 5 additions & 3 deletions app/templates/node-server/node-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ app.use(expressSession({

app.use(cookieParser());
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(logger('dev'));

app.use('/api', require('./routes'));

app.use('/v1', require('./proxy'));

// [GJo] (#31) Moved this till after /v1 proxying, otherwise it might try to parse uploaded binaries as json..
app.use(bodyParser.json());

app.use('/api', require('./routes'));

app.use('/create', express.static('./build/index.html'));
app.use('/profile', express.static('./build/index.html'));

Expand Down
16 changes: 12 additions & 4 deletions app/templates/node-server/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ router.post('*', function(req, res) {
}
});

// (#176) Require authentication for DELETE requests
router.delete('*', function(req, res) {
if (req.session.user === undefined) {
res.send(401, 'Unauthorized');
} else {
proxy(req, res);
}
});

function getAuth(options, session) {
var auth = null;
if (session.user !== undefined && session.user.name !== undefined) {
Expand Down Expand Up @@ -86,10 +95,9 @@ function proxy(req, res) {

res.statusCode = response.statusCode;

// some requests (POST /v1/documents) return a location header. Make sure
// that gets back to the client.
if (response.headers.location) {
res.header('location', response.headers.location);
// [GJo] (#67) forward all headers from MarkLogic
for (var header in response.headers) {
res.header(header, response.headers[header]);
}

response.on('data', function(chunk) {
Expand Down

0 comments on commit b36f66b

Please sign in to comment.