Skip to content

Commit

Permalink
Serve the management frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
ShishKabab committed May 18, 2020
1 parent 0c97ee0 commit fe98743
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 57 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ private
lib
cli.config.json*
build
frontend
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@
"koa": "^2.11.0",
"koa-bodyparser": "^4.2.1",
"koa-router": "^8.0.6",
"koa-serve": "^0.1.7",
"koa-session": "^5.12.3",
"koa-socket-2": "^1.2.0",
"koa-static": "^5.0.0",
"koa-static-server": "^1.5.2",
"lodash": "^4.17.10",
"prompt-sync": "^4.2.0",
"sqlite3": "^4.1.1",
Expand Down
3 changes: 3 additions & 0 deletions ts/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export const COMMANDS: Commands = {
console.error(`Could retrieve app config: ${response.status}`)
}
},
'plugins:list': async (args, { client }) => {
console.log(await client.listPlugins())
},
'plugins:inspect': async (args, { client }) => {
const location = path.resolve(args.path)
// await client.inspectPlugin({ location })
Expand Down
5 changes: 5 additions & 0 deletions ts/cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ export function parseArgs(args: string[]): { appArgs: AppArgs, commandArgs: (Com
default: false
},
})
.command({
command: 'plugin:list',
describe: 'List plugins',
handler: commandHandler('plugins:list')
})
.command({
command: 'plugin:inspect <path>',
describe: 'Install a new plugin',
Expand Down
1 change: 1 addition & 0 deletions ts/cli/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { StorexHubApi_v0 } from "../public-api"
export type Command<Args> = (args: Args, input: { client: StorexHubApi_v0 }) => Promise<void>
export type Commands = { [Name in keyof CommandArgs]: Command<CommandArgs[Name]> }
export interface CommandArgs {
'plugins:list': {},
'plugins:inspect': { path: string },
'plugins:install': { path: string },
'apps:config:set': { app: string, key: string, value: string },
Expand Down
9 changes: 7 additions & 2 deletions ts/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ let storageBackendsCreated = 0

export async function main(options?: {
runtimeConfig?: RuntimeConfig,
frontedDir?: string
frontendDir?: string
withoutServer?: boolean
}) {
const runtimeConfig = options?.runtimeConfig ?? getRuntimeConfig()
const application = await setupApplication(runtimeConfig)
if (!options?.withoutServer) {
await startServer(application, { frontendDir: options?.frontedDir })
let frontendDir = options?.frontendDir
if (!frontendDir) {
frontendDir = path.join(__dirname, '..', 'frontend')
}
await startServer(application, { frontendDir })
}
return { application }
}
Expand Down Expand Up @@ -58,6 +62,7 @@ export async function startServer(application: Application, options: { frontendD
const port = getPortNumber()
await server.start({ port })
console.log(`Server started at http://localhost:${port}`)
console.log(`You can find the management UI at http://localhost:${port}/management/`)
return server
}

Expand Down
11 changes: 8 additions & 3 deletions ts/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import Koa from 'koa'
import Router from 'koa-router'
import session from 'koa-session'
import bodyParser from 'koa-bodyparser'
const serve = require('koa-serve')
const serve = require('koa-static-server')
const IO = require('koa-socket-2')
import { Application } from "../application";
import { STOREX_HUB_API_v0, StorexHubApi_v0, StorexHubCallbacks_v0, AllStorexHubCallbacks_v0 } from '../public-api';
import { Server } from 'http'
import { SocketSessionMap } from './socket-session-map'
import { Session } from '../session'

export async function createHttpServer(application: Application, options: {
secretKey: string,
Expand All @@ -23,7 +22,13 @@ export async function createHttpServer(application: Application, options: {
app.keys = [options.secretKey]
app.use(bodyParser())
app.use(session({}, app))
// app.use(koaStatic())
if (options.frontendDir) {
console.log(options.frontendDir)
app.use(serve({
rootDir: options.frontendDir,
rootPath: '/management'
}))
}

const io = new IO() as SocketIO.Server
io.attach(app)
Expand Down
62 changes: 12 additions & 50 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1155,13 +1155,6 @@ [email protected], debug@~3.1.0:
dependencies:
ms "2.0.0"

debug@^2.2.0, debug@^2.6.9:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
integrity sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==
dependencies:
ms "2.0.0"

debug@^3.1.0, debug@^3.2.6:
version "3.2.6"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b"
Expand Down Expand Up @@ -2414,14 +2407,6 @@ koa-router@^8.0.6:
path-to-regexp "1.x"
urijs "^1.19.2"

koa-send@^1.3.1:
version "1.3.2"
resolved "https://registry.yarnpkg.com/koa-send/-/koa-send-1.3.2.tgz#df1c955b43b77a509067d477f6335907661f5d5e"
integrity sha512-3p4FrvqwxbuJdVnsxIH3HtYcaj/FlxVqrQ66t7hrWkxCnD3ulcOksjq290JJFYtN5Gwn0dqKChn9dMDZ27WVpw==
dependencies:
debug "^2.6.9"
mz "^1.0.1"

koa-send@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/koa-send/-/koa-send-5.0.0.tgz#5e8441e07ef55737734d7ced25b842e50646e7eb"
Expand All @@ -2432,15 +2417,6 @@ koa-send@^5.0.0:
mz "^2.7.0"
resolve-path "^1.4.0"

koa-serve@^0.1.7:
version "0.1.7"
resolved "https://registry.yarnpkg.com/koa-serve/-/koa-serve-0.1.7.tgz#f4432ab769a52430d60992cb9398b040b94344e1"
integrity sha1-9EMqt2mlJDDWCZLLk5iwQLlDROE=
dependencies:
debug "^2.2.0"
koa-send "^1.3.1"
lodash "^3.10.1"

koa-session@^5.12.3:
version "5.12.3"
resolved "https://registry.yarnpkg.com/koa-session/-/koa-session-5.12.3.tgz#c3a10b5195e1f49d13cf48e78efd6724599e16d7"
Expand All @@ -2459,13 +2435,13 @@ koa-socket-2@^1.2.0:
koa-compose "^4.1.0"
socket.io "^2.2.0"

koa-static@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/koa-static/-/koa-static-5.0.0.tgz#5e92fc96b537ad5219f425319c95b64772776943"
integrity sha512-UqyYyH5YEXaJrf9S8E23GoJFQZXkBVJ9zYYMPGz919MSX1KuvAcycIuS0ci150HCoPf4XQVhQ84Qf8xRPWxFaQ==
koa-static-server@^1.5.2:
version "1.5.2"
resolved "https://registry.yarnpkg.com/koa-static-server/-/koa-static-server-1.5.2.tgz#f134979a33530befbe71148441c1cd67f5c271df"
integrity sha512-qIlok7DB85k9ST0cBBdzrYD9j3JwfGJx9D3znDRzdYUwlxix5+czgPlyXy5zW077WRrRzQy0ykx1U6cbaEOPtA==
dependencies:
debug "^3.1.0"
koa-send "^5.0.0"
upath "^1.0.2"

koa@^2.11.0:
version "2.11.0"
Expand Down Expand Up @@ -2552,11 +2528,6 @@ lodash.sortby@^4.7.0:
resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"
integrity sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=

lodash@^3.10.1:
version "3.10.1"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"
integrity sha1-W/Rejkm6QYnhfUgnid/RW9FAt7Y=

lodash@^4.17.10, lodash@^4.17.13, lodash@^4.17.15:
version "4.17.15"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
Expand Down Expand Up @@ -2771,15 +2742,6 @@ multistream@^2.1.1:
inherits "^2.0.1"
readable-stream "^2.0.5"

mz@^1.0.1:
version "1.3.0"
resolved "https://registry.yarnpkg.com/mz/-/mz-1.3.0.tgz#06f093fdd9956a06d37e1b1e81344e27478c42f0"
integrity sha1-BvCT/dmVagbTfhsegTROJ0eMQvA=
dependencies:
native-or-bluebird "1"
thenify "3"
thenify-all "1"

mz@^2.4.0, mz@^2.7.0:
version "2.7.0"
resolved "https://registry.yarnpkg.com/mz/-/mz-2.7.0.tgz#95008057a56cafadc2bc63dde7f9ff6955948e32"
Expand All @@ -2794,11 +2756,6 @@ nan@^2.12.1:
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.0.tgz#7818f722027b2459a86f0295d434d1fc2336c52c"
integrity sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==

native-or-bluebird@1:
version "1.2.0"
resolved "https://registry.yarnpkg.com/native-or-bluebird/-/native-or-bluebird-1.2.0.tgz#39c47bfd7825d1fb9ffad32210ae25daadf101c9"
integrity sha1-OcR7/Xgl0fuf+tMiEK4l2q3xAck=

needle@^2.2.1:
version "2.4.0"
resolved "https://registry.yarnpkg.com/needle/-/needle-2.4.0.tgz#6833e74975c444642590e15a750288c5f939b57c"
Expand Down Expand Up @@ -4115,14 +4072,14 @@ test-exclude@^5.1.0:
read-pkg-up "^4.0.0"
require-main-filename "^2.0.0"

thenify-all@1, thenify-all@^1.0.0:
thenify-all@^1.0.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/thenify-all/-/thenify-all-1.6.0.tgz#1a1918d402d8fc3f98fbf234db0bcc8cc10e9726"
integrity sha1-GhkY1ALY/D+Y+/I02wvMjMEOlyY=
dependencies:
thenify ">= 3.1.0 < 4"

thenify@3, "thenify@>= 3.1.0 < 4":
"thenify@>= 3.1.0 < 4":
version "3.3.0"
resolved "https://registry.yarnpkg.com/thenify/-/thenify-3.3.0.tgz#e69e38a1babe969b0108207978b9f62b88604839"
integrity sha1-5p44obq+lpsBCCB5eLn2K4hgSDk=
Expand Down Expand Up @@ -4358,6 +4315,11 @@ untildify@^3.0.2:
resolved "https://registry.yarnpkg.com/untildify/-/untildify-3.0.3.tgz#1e7b42b140bcfd922b22e70ca1265bfe3634c7c9"
integrity sha512-iSk/J8efr8uPT/Z4eSUywnqyrQU7DSdMfdqK4iWEaUVVmcP5JcnpRqmVMwcwcnmI1ATFNgC5V90u09tBynNFKA==

upath@^1.0.2:
version "1.2.0"
resolved "https://registry.yarnpkg.com/upath/-/upath-1.2.0.tgz#8f66dbcd55a883acdae4408af8b035a5044c1894"
integrity sha512-aZwGpamFO61g3OlfT7OQCHqhGnW43ieH9WZeP7QxN/G/jS4jfqUkZxoryvJgVPEcrl5NL/ggHsSmLMHuH64Lhg==

uri-js@^4.2.2:
version "4.2.2"
resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.2.2.tgz#94c540e1ff772956e2299507c010aea6c8838eb0"
Expand Down

0 comments on commit fe98743

Please sign in to comment.