-
Notifications
You must be signed in to change notification settings - Fork 1
/
PageController.js
73 lines (61 loc) · 2.28 KB
/
PageController.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* PageController
*
* This file was added for the AppBuilder production docker image.
*
* @module :: Controller
* @description :: A set of functions called `actions`.
*
* Actions contain code telling Sails how to respond to a certain type of request.
* (i.e. do stuff, then send some JSON, show an HTML page, or redirect to another URL)
*
* You can configure the blueprint URLs which trigger these actions (`config/controllers.js`)
* and/or override them with custom routes (`config/routes.js`)
*
* NOTE: The code you write here supports both HTTP and Socket.io automatically.
*
* @docs :: http://sailsjs.org/#!documentation/controllers
*/
var fs = require("fs");
var path = require("path");
var packageVersion = require("../../node_modules/app_builder/package.json");
sails.config.appdev.version = (packageVersion && packageVersion.version) ? packageVersion.version : "0.0.0";
module.exports = {
/**
* Overrides for the settings in `config/controllers.js`
* (specific to PageController)
*/
_config: {},
pageAsset:function(req,res) {
// route : /page/*/*
var urlParts = req.url.split('/');
// remove 'page'
var value = urlParts.shift();
if (value == '') urlParts.shift();
// if this maps to a normal asset
var assetPath = path.join('assets', urlParts.join(path.sep));
fs.exists(assetPath,function (exists) {
if (exists) {
// just return that file
res.sendfile(assetPath);
} else {
// this is a page/[pageName]/[file] request:
var filePath = path.join('assets', 'page', urlParts.join(path.sep));
res.sendfile(filePath);
}
});
},
// Landing page as configured in config/routes.js
// route: /
opsportal: function(req, res) {
// EJS view file "/app/views/page/opsportal.ejs" must exist even though
// it is not actually used.
res.view({
Title: 'AppBuilder',
Description: 'AppBuilder production landing page',
// This is usually defined in config/appdev.js
// sails.config.appdev.defaultLandingView
layout: 'appdev-core/adcore/landing.ejs'
});
},
};