Skip to content

Commit

Permalink
feat(index): add service listing, require service id
Browse files Browse the repository at this point in the history
  • Loading branch information
wzr1337 committed Jan 21, 2017
1 parent 6869f05 commit 4710047
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,19 @@ const BASEURI = "/";

var unsubscriptions:Subject<string> = new Subject();

var services:{id:string,name:string,uri:string}[] = [];

// set up the server
var server = new WebServer();
server.init(); // need to init
server.app.get(BASEURI, (req: express.Request, res: express.Response, next: express.NextFunction) => {
// respond
res.status(200);
res.json({
status: "ok",
data: services
});
});


/**
Expand All @@ -34,9 +44,14 @@ fs.readdir(path.join(__dirname, "plugins"), (err:NodeJS.ErrnoException, files: s
if(fs.lstatSync(plugin).isDirectory()) {
let _plugin = require(plugin);
let service:Service = new _plugin();
services.push({
id: service.id,
name: service.name,
uri: BASEURI + service.name.toLowerCase() + "/"
});
console.log("Loading Plugin:", service.name);
service.resources.map((resource:Resource) => {
let basePath = "/" + service.name.toLowerCase() + "/" + resource.name.toLowerCase() + "/";
let basePath = BASEURI + service.name.toLowerCase() + "/" + resource.name.toLowerCase() + "/";
server.app.get(basePath, resourceGET(service, resource)); //READ
server.app.post(basePath, resourcePOST(service, resource)); //CREATE
server.app.post(basePath + ':id', elementPOST(service, resource)); //READ
Expand Down
8 changes: 7 additions & 1 deletion src/plugins/media/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@ import { Service, Resource } from "../viwiPlugin";

class Media implements Service {
private _resources:Resource[]=[];
private _id:string;

constructor() {
this._id = "f9a1073f-e90c-4c56-8368-f4c6bd1d8c96"; //random id
this._resources.push(new Renderers(this));
this._resources.push(new Collections(this))
this._resources.push(new Collections(this));
}

get name() {
return this.constructor.name;
}

get id() {
return this._id;
}

get resources() {
return this._resources;
}
Expand Down
1 change: 1 addition & 0 deletions src/plugins/viwiPlugin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ declare namespace viwiPlugin {

interface Service {
name:string;
id: string;
resources:Resource[];
}

Expand Down

0 comments on commit 4710047

Please sign in to comment.