Merge branch 'julius-dev' of Software_Engineering_I/greenvironment-server into develop
commit
527df6499e
@ -0,0 +1,27 @@
|
|||||||
|
/**
|
||||||
|
* @author Trivernis
|
||||||
|
* @remarks
|
||||||
|
*
|
||||||
|
* Taken from {@link https://github.com/Trivernis/whooshy}
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {Router} from "express";
|
||||||
|
import {Namespace, Server} from "socket.io";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract Route class to be implemented by each route.
|
||||||
|
* This class contains the socket-io Server, router and resolver
|
||||||
|
* for each route.
|
||||||
|
*/
|
||||||
|
abstract class Route {
|
||||||
|
|
||||||
|
public router?: Router;
|
||||||
|
protected io?: Server;
|
||||||
|
protected ions?: Namespace;
|
||||||
|
|
||||||
|
public abstract async init(...params: any): Promise<any>;
|
||||||
|
public abstract async destroy(...params: any): Promise<any>;
|
||||||
|
public abstract async resolver(request: any, response: any): Promise<object>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Route;
|
@ -1,10 +1,55 @@
|
|||||||
import {Router} from "express";
|
import {Router} from "express";
|
||||||
|
import {Server} from "socket.io";
|
||||||
|
import Route from "../lib/Route";
|
||||||
|
|
||||||
const router = Router();
|
/**
|
||||||
|
* Class for the home route.
|
||||||
|
*/
|
||||||
|
class HomeRoute extends Route {
|
||||||
|
/**
|
||||||
|
* Constructor, creates new router.
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.router = Router();
|
||||||
|
this.configure();
|
||||||
|
}
|
||||||
|
|
||||||
/* GET home page. */
|
/**
|
||||||
router.get("/", (req, res) => {
|
* Asynchronous init for socket.io.
|
||||||
|
* @param io - the io instance
|
||||||
|
*/
|
||||||
|
public async init(io: Server) {
|
||||||
|
this.io = io;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroys the instance by dereferencing the router and resolver.
|
||||||
|
*/
|
||||||
|
public async destroy(): Promise<void> {
|
||||||
|
this.router = null;
|
||||||
|
this.resolver = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the resolvers for the graphql api.
|
||||||
|
* @param req - the request object
|
||||||
|
* @param res - the response object
|
||||||
|
*/
|
||||||
|
public async resolver(req: any, res: any): Promise<object> {
|
||||||
|
return {
|
||||||
|
// TODO: Define grapql resolvers
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures the route.
|
||||||
|
*/
|
||||||
|
private configure() {
|
||||||
|
this.router.get("/", (req, res) => {
|
||||||
res.render("home");
|
res.render("home");
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default router;
|
export default HomeRoute;
|
||||||
|
Loading…
Reference in New Issue