Change routes structure

- Rename home to HomeRoute
- Rename upload to UploadRoute
- Remove index.ts
- Remove unused imports
pull/4/head
Trivernis 5 years ago
parent e413e76321
commit 827ac1ff95

@ -3,8 +3,6 @@ import * as cookieParser from "cookie-parser";
import * as cors from "cors";
import {Request, Response} from "express";
import * as express from "express";
import {UploadedFile} from "express-fileupload";
import * as fileUpload from "express-fileupload";
import * as graphqlHTTP from "express-graphql";
import * as session from "express-session";
import sharedsession = require("express-socket.io-session");
@ -15,15 +13,13 @@ import * as http from "http";
import * as httpStatus from "http-status";
import * as path from "path";
import {Sequelize} from "sequelize-typescript";
import * as sharp from "sharp";
import * as socketIo from "socket.io";
import * as socketIoRedis from "socket.io-redis";
import {resolver} from "./graphql/resolvers";
import dataaccess from "./lib/dataAccess";
import globals from "./lib/globals";
import {User} from "./lib/models";
import routes from "./routes";
import {UploadRoute} from "./routes/upload";
import HomeRoute from "./routes/HomeRoute";
import {UploadRoute} from "./routes/UploadRoute";
const SequelizeStore = require("connect-session-sequelize")(session.Store);
const logger = globals.logger;
@ -65,13 +61,10 @@ class App {
secret: globals.config.session.secret,
store: new SequelizeStore({db: this.sequelize}),
});
const uploadRoute = new UploadRoute(this.publicPath);
await uploadRoute.init();
await this.sequelize.sync({ logging: (msg) => logger.silly(msg)});
this.sequelize.options.logging = (msg) => logger.silly(msg);
logger.info("Setting up socket.io");
await routes.ioListeners(this.io);
try {
this.io.adapter(socketIoRedis());
} catch (err) {
@ -116,8 +109,18 @@ class App {
logger.verbose(`${req.method} ${req.url}`);
next();
});
this.app.use(routes.router);
// add custom routes
const uploadRoute = new UploadRoute(this.publicPath);
const homeRoute = new HomeRoute();
await uploadRoute.init();
await homeRoute.init(this.io);
this.app.use("/home", homeRoute.router);
this.app.use("/upload", uploadRoute.router);
// listen for graphql requests
this.app.use("/graphql", graphqlHTTP((request, response) => {
return {

@ -1,14 +1,14 @@
import * as crypto from "crypto";
import {Router} from "express";
import * as fileUpload from "express-fileupload";
import {UploadedFile} from "express-fileupload";
import {User} from "../lib/models";
import Route from "../lib/Route";
import * as fsx from "fs-extra";
import globals from "../lib/globals";
import * as path from "path";
import * as crypto from "crypto";
import * as fileUpload from "express-fileupload";
import * as status from "http-status";
import * as path from "path";
import * as sharp from "sharp";
import globals from "../lib/globals";
import {User} from "../lib/models";
import Route from "../lib/Route";
const dataDirName = "data";

@ -1,35 +0,0 @@
/**
* @author Trivernis
* @remarks
*
* Taken from {@link https://github.com/Trivernis/whooshy}
*/
import {Router} from "express";
import {Server} from "socket.io";
import HomeRoute from "./home";
import {UploadRoute} from "./upload";
const homeRoute = new HomeRoute();
/**
* Namespace to manage the routes of the server.
* Allows easier assignments of graphql endpoints, socket.io connections and routers when
* used with {@link Route}.
*/
namespace routes {
export const router = Router();
router.use("/", homeRoute.router);
/**
* Assigns the io listeners or namespaces to the routes
* @param io
*/
export const ioListeners = async (io: Server) => {
await homeRoute.init(io);
};
}
export default routes;
Loading…
Cancel
Save