aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
authoranika-ahluwalia <anika.ahluwalia@gmail.com>2020-04-18 17:56:30 -0500
committeranika-ahluwalia <anika.ahluwalia@gmail.com>2020-04-18 17:56:30 -0500
commit04e2cdc30dd71cccb066f713a93cdc4d3bbd169c (patch)
treeebacc25b4b99ac74b4bf79c12d0ae17a46033b0b /src/server
parenta261ab5e9697277bec029803f1fa0c890f0c8fd5 (diff)
parent9f8e76451b807ed8f51ef32aab9b2255dfccd525 (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into script_documents
Diffstat (limited to 'src/server')
-rw-r--r--src/server/authentication/models/current_user_utils.ts6
-rw-r--r--src/server/database.ts18
-rw-r--r--src/server/index.ts10
3 files changed, 24 insertions, 10 deletions
diff --git a/src/server/authentication/models/current_user_utils.ts b/src/server/authentication/models/current_user_utils.ts
index 5e806d2d2..9235a97b0 100644
--- a/src/server/authentication/models/current_user_utils.ts
+++ b/src/server/authentication/models/current_user_utils.ts
@@ -342,9 +342,11 @@ export class CurrentUserUtils {
const openInTarget = Docs.Create.ScriptingDocument(ScriptField.MakeScript(
"docCast(thisContainer.target).then((target) => { target && docCast(this.source).then((source) => { target.proto.data = new List([source || this]); } ); } )",
{ target: Doc.name }), { title: "On Child Clicked (open in target)", _width: 300, _height: 200 });
- const onClick = Docs.Create.ScriptingDocument(ScriptField.MakeScript("console.log('click')"), { title: "onClick", isTemplateDoc: true, isTemplateForField: "onClick", _width: 300, _height: 200 }, "onClick");
+ const onClick = Docs.Create.ScriptingDocument(undefined, { title: "onClick", "onClick-rawScript": "console.log('click')", isTemplateDoc: true, isTemplateForField: "onClick", _width: 300, _height: 200 }, "onClick");
+ const onCheckedClick = Docs.Create.ScriptingDocument(undefined,
+ { title: "onCheckedClick", "onCheckedClick-rawScript": "console.log(heading + checked + containingTreeView)", "onCheckedClick-params": new List<string>(["heading", "checked", "containingTreeView"]), isTemplateDoc: true, isTemplateForField: "onCheckedClick", _width: 300, _height: 200 }, "onCheckedClick");
doc.childClickFuncs = Docs.Create.TreeDocument([openInTarget], { title: "on Child Click function templates" });
- doc.clickFuncs = Docs.Create.TreeDocument([onClick], { title: "onClick funcs" });
+ doc.clickFuncs = Docs.Create.TreeDocument([onClick, onCheckedClick], { title: "onClick funcs" });
}
static updateUserDocument(doc: Doc) {
diff --git a/src/server/database.ts b/src/server/database.ts
index a46531641..1da31c5ff 100644
--- a/src/server/database.ts
+++ b/src/server/database.ts
@@ -14,7 +14,7 @@ export namespace Database {
export let disconnect: Function;
const schema = 'Dash';
const port = 27017;
- export const url = `mongodb://localhost:${port}/${schema}`;
+ export const url = `mongodb://localhost:${port}/`;
enum ConnectionStates {
disconnected = 0,
@@ -35,7 +35,7 @@ export namespace Database {
console.log(`mongoose established default connection at ${url}`);
resolve();
});
- mongoose.connect(url, { useNewUrlParser: true });
+ mongoose.connect(url, { useNewUrlParser: true, useUnifiedTopology: true, dbName: schema });
});
}
} catch (e) {
@@ -46,17 +46,22 @@ export namespace Database {
}
}
- class Database implements IDatabase {
+ export class Database implements IDatabase {
public static DocumentsCollection = 'documents';
private MongoClient = mongodb.MongoClient;
private currentWrites: { [id: string]: Promise<void> } = {};
private db?: mongodb.Db;
private onConnect: (() => void)[] = [];
-
constructor() {
- this.MongoClient.connect(url, { connectTimeoutMS: 30000, socketTimeoutMS: 30000 }, (_err, client) => {
+ }
+
+ doConnect() {
+ console.error(`\nConnecting to Mongo with URL : ${url}\n`);
+ this.MongoClient.connect(url, { connectTimeoutMS: 30000, socketTimeoutMS: 30000, useUnifiedTopology: true }, (_err, client) => {
+ console.error("mongo connect response\n");
if (!client) {
- console.error("\nPlease start MongoDB by running 'mongod' in a terminal before continuing...\n");
+ console.error("\nMongo connect failed with the error:\n");
+ console.log(_err);
process.exit(0);
}
this.db = client.db();
@@ -65,6 +70,7 @@ export namespace Database {
}
public async update(id: string, value: any, callback: (err: mongodb.MongoError, res: mongodb.UpdateWriteOpResult) => void, upsert = true, collectionName = Database.DocumentsCollection) {
+
if (this.db) {
const collection = this.db.collection(collectionName);
const prom = this.currentWrites[id];
diff --git a/src/server/index.ts b/src/server/index.ts
index 8b040c926..f26c8a6ab 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -106,12 +106,17 @@ function routeSetter({ isRelease, addSupervisedRoute, logRegistrationOutcome }:
method: Method.GET,
subscription: ["/home", new RouteSubscriber("doc").add("docId")],
secureHandler: serve,
- publicHandler: ({ req, ...remaining }) => {
+ publicHandler: ({ req, res, ...remaining }) => {
const { originalUrl: target } = req;
const sharing = qs.parse(qs.extract(req.originalUrl), { sort: false }).sharing === "true";
const docAccess = target.startsWith("/doc/");
+ // since this is the public handler, there's no meaning of '/home' to speak of
+ // since there's no user logged in, so the only viable operation
+ // for a guest is to look at a shared document
if (sharing && docAccess) {
- serve({ req, ...remaining });
+ serve({ req, res, ...remaining });
+ } else {
+ res.redirect("/login");
}
}
});
@@ -148,5 +153,6 @@ export async function launchServer() {
if (process.env.RELEASE) {
(sessionAgent = new DashSessionAgent()).launch();
} else {
+ (Database.Instance as Database.Database).doConnect();
launchServer();
}