Merge branch 'v1' of git.daplie.com:Daplie/walnut.js into v1

This commit is contained in:
AJ ONeal 2017-06-14 18:37:34 -06:00
commit 54376f3157
3 changed files with 57 additions and 11 deletions

View File

@ -56,6 +56,11 @@ In Progress
* [GunDB](https://gundb.io) Support
* OpenID support
API
---
API docs are here https://git.daplie.com/Daplie/com.example.hello
Structure
=====
@ -69,12 +74,15 @@ Currently being tested with Ubuntu, Raspbian, and Debian on Digital Ocean, Raspb
│ ├── boot
│ ├── holepunch
│ └── lib
├── etc
│ └── client-api-grants
├── node_modules
├── packages
│ ├── apis
│ ├── pages
│ └── services
└── var
└── sites
```
* `core` contains all walnut code
@ -243,3 +251,10 @@ The permissions:
com.example.hello # refers to /srv/walnut/packages/pages/com.example.hello
'''
```
API
---
```
req.apiUrlPrefix => https://api.example.com/api/tld.domain.pkg
```

View File

@ -219,16 +219,19 @@ my_app_launchd_service="Library/LaunchDaemons/${my_app_pkg_name}.plist"
# Install
install_my_app()
{
# This function shouldn't need to use $sudo_cmd because it is called immediately after
# /srv/walnut is chown-ed and we only mess with things in that directory.
#git clone git@git.daplie.com:Daplie/walnut.js.git
#git clone https://git.daplie.com/Daplie/walnut.js.git /srv/walnut/core
sudo mkdir -p /srv/walnut/{core,lib,var,etc,node_modules}
mkdir -p /srv/walnut/{core,lib,var,etc,node_modules}
rm -rf /srv/walnut/core/node_modules
ln -sf ../node_modules /srv/walnut/core/node_modules
sudo mkdir -p /srv/walnut/var/sites
sudo mkdir -p /srv/walnut/etc/org.oauth3.consumer
sudo mkdir -p /srv/walnut/etc/org.oauth3.provider
sudo mkdir -p /srv/walnut/etc/client-api-grants
sudo mkdir -p /srv/walnut/packages/{rest,api,pages,services}
mkdir -p /srv/walnut/var/sites
mkdir -p /srv/walnut/etc/org.oauth3.consumer
mkdir -p /srv/walnut/etc/org.oauth3.provider
mkdir -p /srv/walnut/etc/client-api-grants
mkdir -p /srv/walnut/packages/{rest,api,pages,services}
# backwards compat
if [ -d /srv/walnut/packages/client-api-grants ]; then
@ -249,14 +252,14 @@ install_my_app()
popd
}
sudo mkdir -p /srv/walnut
sudo chown -R $(whoami) /srv/walnut
$sudo_cmd mkdir -p /srv/walnut
$sudo_cmd chown -R $(whoami) /srv/walnut
install_my_app
create_skeleton
install_uninstaller
install_service
sudo chown -R www-data:www-data /srv/walnut || true
sudo chown -R _www:_www /srv/walnut || true
sudo chmod -R ug+rwX /srv/walnut
$sudo_cmd chown -R www-data:www-data /srv/walnut || true
$sudo_cmd chown -R _www:_www /srv/walnut || true
$sudo_cmd chmod -R ug+rwX /srv/walnut

View File

@ -318,6 +318,7 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
var _stripe_test;
var _mandrill;
var _mailchimp;
var _twilio;
myApp.use('/', function preHandler(req, res, next) {
return getSiteConfig(clientUrih).then(function (siteConfig) {
Object.defineProperty(req, 'getSiteMailer', {
@ -429,6 +430,27 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
}
});
var caps = {
'com.daplie.tel.twilio': function (/*opts*/) {
if (_twilio) {
return _twilio;
}
var Twilio = require('twilio');
_twilio = new Twilio.RestClient(siteConfig['twilio.com'].id, siteConfig['twilio.com'].auth);
return apiDeps.Promise.resolve(_twilio);
}
};
req.getSiteCapability = function (capname, opts) {
if (caps[capname]) {
return caps[capname](opts);
}
return apiDeps.Promise.reject(
new Error("['" + req.clientApiUri + '/' + pkgId + "'] "
+ "capability '" + capname + "' not implemented")
);
};
req._walnutOriginalUrl = req.url;
// "/path/api/com.example/hello".replace(/.*\/api\//, '').replace(/([^\/]*\/+)/, '/') => '/hello'
req.url = req.url.replace(/\/api\//, '').replace(/.*\/api\//, '').replace(/([^\/]*\/+)/, '/');
@ -517,6 +539,12 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
var hasBeenHandled = false;
// Existing (Deprecated)
Object.defineProperty(req, 'apiUrlPrefix', {
enumerable: true
, configurable: false
, writable: false
, value: 'https://' + clientApiUri + '/' + pkgId
});
Object.defineProperty(req, 'experienceId', {
enumerable: true
, configurable: false