From b6c758f2fc2cb502ed194f2700e033564f2521f4 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Tue, 22 Sep 2015 12:06:13 +0800 Subject: Added server option "useCdn", use template statement to route resources' source --- README.md | 1 + app.js | 4 +- config.js | 1 + lib/response.js | 13 +++ public/index.ejs | 240 ++++++++++++++++++++++++++++++++++++++++++++++++ public/index.html | 223 -------------------------------------------- public/views/foot.ejs | 9 ++ public/views/head.ejs | 8 +- public/views/pretty.ejs | 14 ++- 9 files changed, 284 insertions(+), 229 deletions(-) create mode 100644 public/index.ejs delete mode 100644 public/index.html diff --git a/README.md b/README.md index ffefafa2..aa051e9b 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ Server-side config.js settings | usessl | `true` or `false` | set to use ssl | | urladdport | `true` or `false` | set to add port on oauth callback url | | debug | `true` or `false` | set debug mode, show more logs | +| usecdn | `true` or `false` | set to use CDN resources or not | | version | `0.3.2` | currnet version, must match same var in client side `index.js` | | alloworigin | `['localhost']` | domain name whitelist | | sslkeypath | `./cert/client.key` | ssl key path | diff --git a/app.js b/app.js index 628f4631..a19715fe 100644 --- a/app.js +++ b/app.js @@ -136,9 +136,7 @@ app.set('views', __dirname + '/public'); //set render engine app.engine('html', ejs.renderFile); //get index -app.get("/", function (req, res, next) { - res.render("index.html"); -}); +app.get("/", response.showIndex); //get status app.get("/status", function (req, res, next) { realtime.getStatus(function (data) { diff --git a/config.js b/config.js index cfd9f20d..b04066da 100644 --- a/config.js +++ b/config.js @@ -11,6 +11,7 @@ var urladdport = true; //add port on getserverurl var config = { debug: true, + usecdn: false, version: '0.3.2', domain: domain, alloworigin: ['add here to allow origin to cross'], diff --git a/lib/response.js b/lib/response.js index b8cfab17..1f7fbd54 100644 --- a/lib/response.js +++ b/lib/response.js @@ -34,6 +34,7 @@ var response = { showFeatures: showFeatures, showNote: showNote, showPublishNote: showPublishNote, + showIndex: showIndex, noteActions: noteActions, publishNoteActions: publishNoteActions }; @@ -55,6 +56,18 @@ function responseError(res, code, detail, msg) { res.end(); } +function showIndex(req, res, next) { + res.writeHead(200, { + 'Content-Type': 'text/html' + }); + var template = config.indexpath; + var content = ejs.render(fs.readFileSync(template, 'utf8'), { + useCDN: config.usecdn + }); + res.write(content); + res.end(); +} + function responseHackMD(res, noteId) { if (noteId != config.featuresnotename) { if (!Note.checkNoteIdValid(noteId)) { diff --git a/public/index.ejs b/public/index.ejs new file mode 100644 index 00000000..dbc5e268 --- /dev/null +++ b/public/index.ejs @@ -0,0 +1,240 @@ + + + +
+ + + + + + + + ++ Realtime collaborative markdown notes on all platforms. +
+ + ++ Start new note +
+ See all features here +- Realtime collaborative markdown notes on all platforms. -
- - -- Start new note -
- See all features here -