Skip to content
This repository was archived by the owner on Oct 5, 2020. It is now read-only.

Commit 9dfd430

Browse files
committed
Some final refinements on the node-server
1 parent f2072d6 commit 9dfd430

File tree

5 files changed

+14
-55
lines changed

5 files changed

+14
-55
lines changed

app/templates/gulpfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ function getNodeOptions(env) {
761761
delayTime: 1,
762762
env: {
763763
'PORT': port,
764-
'NODE_ENV': isDevMode(env) ? 'dev' : 'build',
764+
'NODE_ENV': env,
765765
'APP_PORT': port,
766766
'ML_HOST': args['ml-host'] || process.env.ML_HOST || envJson['ml-host'] || config.marklogic.host,
767767
'ML_APP_USER': args['ml-app-user'] || process.env.ML_APP_USER || envJson['ml-app-user'] || config.marklogic.user,
@@ -870,7 +870,7 @@ function startTests(singleRun, done) {
870870
if (args.startServers) {
871871
log('Starting servers');
872872
var savedEnv = process.env;
873-
savedEnv.NODE_ENV = 'dev';
873+
savedEnv.NODE_ENV = 'local';
874874
savedEnv.PORT = 8888;
875875
child = fork(config.nodeServer);
876876
} else {

app/templates/node-server/node-app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ console.log('NODE_ENV=' + environment);
3030
switch (environment){
3131
case 'prod':
3232
case 'dev':
33-
console.log('** BUILD **');
33+
console.log('** DIST **');
3434
app.use(express.static('./dist/'));
3535
// Any invalid calls for templateUrls are under app/* and should return 404
3636
app.use('/app/*', function(req, res, next) {
@@ -40,7 +40,7 @@ switch (environment){
4040
app.use('/*', express.static('./dist/index.html'));
4141
break;
4242
default:
43-
console.log('** DEV **');
43+
console.log('** UI **');
4444
app.use(express.static('./ui/'));
4545
app.use(express.static('./')); // for bower_components
4646
app.use(express.static('./tmp'));

app/templates/node-server/proxy.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var options = require('./utils/options')();
2222
// For any other GET request, proxy it on to MarkLogic.
2323
router.get('*', function(req, res) {
2424
noCache(res);
25-
if (!options.guestAccess && req.session.user === undefined) {
25+
if (!options.guestAccess && (req.session.user === undefined)) {
2626
res.status(401).send('Unauthorized');
2727
} else {
2828
proxy(req, res);
@@ -35,24 +35,21 @@ router.put('*', function(req, res) {
3535
// For PUT requests, require authentication
3636
if (req.session.user === undefined) {
3737
res.status(401).send('Unauthorized');
38-
} else if (options.disallowUpdates || (req.path === '/v1/documents' &&
38+
} else if (options.disallowUpdates || ((req.path === '/documents') &&
3939
req.query.uri.match('/api/users/') &&
40-
req.query.uri.match(new RegExp('/api/users/[^(' + req.session.user.username + ')]+.json')))) {
40+
!req.query.uri.match('/api/users/' + req.session.user.username + '.json'))) {
4141
// The user is trying to PUT to a profile document other than his/her own. Not allowed.
4242
res.status(403).send('Forbidden');
4343
} else {
44-
if (req.path === '/v1/documents' && req.query.uri.match('/users/')) {
45-
var json = req.body.user ? req.body : JSON.parse(req.body);
46-
req.session.user.profile = json.user;
47-
}
44+
// proxy original request
4845
proxy(req, res);
4946
}
5047
});
5148

5249
// Require authentication for POST requests
5350
router.post(/^\/(alert\/match|search|suggest|values\/.*)$/, function(req, res) {
5451
noCache(res);
55-
if (!options.guestAccess && req.session.user === undefined) {
52+
if (!options.guestAccess && (req.session.user === undefined)) {
5653
res.status(401).send('Unauthorized');
5754
} else {
5855
proxy(req, res);
@@ -83,7 +80,8 @@ router.delete('*', function(req, res) {
8380

8481
function getAuth(options, session) {
8582
var auth = null;
86-
if (session.user !== undefined && session.user.username !== undefined) {
83+
84+
if ((session.user !== undefined) && (session.user.username !== undefined)) {
8785
auth = session.user.username + ':' + session.user.password;
8886
}
8987
else {

app/templates/node-server/routes.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ router.get('/user/status', function(req, res) {
5757
req.session.user.profile
5858
));
5959
} else {
60-
res.send({authenticated: false});
60+
res.send(authStatus(
61+
false
62+
));
6163
}
6264
});
6365

app/themes/dashboard/ui/index.html

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)