joyent-portal/bundle/index.js

95 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-02-15 22:05:29 +02:00
'use strict';
2018-01-08 17:13:05 +02:00
const Brule = require('brule');
const Hapi = require('hapi');
const Rollover = require('rollover');
2018-02-15 22:05:29 +02:00
const { homedir } = require('os');
const { join } = require('path');
process.env.SDC_KEY_PATH =
process.env.SDC_KEY_PATH || join(homedir(), '.ssh/id_rsa');
2018-01-08 17:13:05 +02:00
2018-02-15 22:05:29 +02:00
const Sso = require('hapi-triton-auth');
2018-01-08 17:13:05 +02:00
const Ui = require('my-joy-beta');
const Nav = require('joyent-navigation');
const Api = require('cloudapi-gql');
const {
PORT = 3069,
COOKIE_PASSWORD,
COOKIE_DOMAIN,
SDC_KEY_PATH,
SDC_ACCOUNT,
SDC_KEY_ID,
SDC_URL,
BASE_URL = `http://0.0.0.0:${PORT}`,
ROLLBAR_SERVER_TOKEN,
NODE_ENV = 'development'
} = process.env;
const server = Hapi.server({
port: PORT,
host: '127.0.0.1'
});
2018-02-15 22:05:29 +02:00
async function main () {
2018-01-08 17:13:05 +02:00
await server.register([
2018-02-15 22:05:29 +02:00
{
plugin: Rollover,
options: {
rollbar: {
accessToken: ROLLBAR_SERVER_TOKEN,
reportLevel: 'error'
}
}
},
2018-01-08 17:13:05 +02:00
{
plugin: Brule,
options: {
auth: false
}
},
{
plugin: Sso,
options: {
cookie: {
password: COOKIE_PASSWORD,
domain: COOKIE_DOMAIN,
isSecure: false,
isHttpOnly: true,
ttl: 1000 * 60 * 60 // 1 hour
},
sso: {
keyPath: SDC_KEY_PATH,
keyId: '/' + SDC_ACCOUNT + '/keys/' + SDC_KEY_ID,
apiBaseUrl: SDC_URL,
url: 'https://sso.joyent.com/login',
permissions: { cloudapi: ['/my/*'] },
baseUrl: BASE_URL,
isDev: NODE_ENV === 'development'
}
}
},
{
plugin: Nav
},
{
plugin: Ui
},
{
plugin: Api
}
]);
server.auth.default('sso');
2018-02-15 22:05:29 +02:00
process.on('unhandledRejection', (err) => {
server.log(['error'], err);
});
2018-01-08 17:13:05 +02:00
await server.start();
console.log(`server started at http://localhost:${server.info.port}`);
2018-02-15 22:05:29 +02:00
}
main();