"use strict";

module.exports = function(imports) {

    let express = imports.modules.express;
    let Promise = imports.modules.Promise;
    let fs = require("fs"); // TODO: put this into initImports
    let util = imports.util;
    let handler = util.handler;

    let router = express.Router();

    router.get(handler(function*(req, res) {

            let pages = {
                signup: "Signup",
            };

            let page = Object.keys(pages)
                .find(page => req.path.substring(1).startsWith(page)));
        if (!page) {
            return next();
        }

        res.render("../../morteam-web/src/page.html.ejs", {
            page: pages[page]
        });

    }));

router.get("/js/:page", handler(function*(req, res) {
    let page = req.params.page;
    let file = "../../morteam-web/build/" + page + ".js";
    // TODO: use the pacakge fs-promise
    fs.exists(file, function(exists) {
        if (!exists) {
            return res.end("fail"); // AHHHH
        }
        fs.createReadStream(file).pipe(res);
    });
}));

return router;

};

@@ -301,73 +301,210 @@
     
-router.get(handler(function*(req, res) %7B%0A%0A            let pages =
+let pages = %7B%0A        signup: %22Signup%22,%0A    %7D;%0A%0A    for (let page in pages) %7B%0A%0A        router.get(%22/%22 + page, handler(function*(req, res) %7B%0A%0A            res.render(%22../../morteam-web/src/page.html.ejs%22,
  %7B%0A 
@@ -518,33 +518,33 @@
         
-signup: %22Signup%22,
+page: pages%5Bpage%5D
 %0A       
@@ -545,24 +545,25 @@
            %7D
+)
 ;%0A%0A         
@@ -565,41 +565,78 @@
     
-    let page = Object.keys(pag
+%7D));%0A%0A    %7D%0A%0A    router.get(%22/js/:page%22, handler(function*(req, r
 es)
+ %7B
 %0A   
@@ -644,89 +644,178 @@
     
-        .find(page =%3E req.path.substring(1).startsWith(page)));%0A        if (!page
+let page = req.params.page;%0A        let file = %22../morteam-web/build/%22 + page + %22.js%22;%0A        // TODO: use the pacakge fs-promise%0A        fs.exists(file, function(exists
 ) %7B%0A
@@ -830,22 +830,22 @@
     
-return next();
+if (!exists) %7B
 %0A   
@@ -853,19 +853,16 @@
     
-%7D%0A%0A
         
 res.
@@ -861,89 +861,103 @@
     
+return 
 res.
-r
 end
-er(%22../../morteam-web/src/page.html.ejs%22, %7B%0A            page: pages%5Bpage%5D
+(%22fail%22); // AHHHH%0A            %7D%0A            fs.createReadStream(file).pipe(res);
 %0A   
@@ -961,25 +961,24 @@
         %7D);%0A
-%0A
     %7D));%0A%0Aro
@@ -979,368 +979,12 @@
 );%0A%0A
-router.get(%22/js/:page%22, handler(function*(req, res) %7B%0A    let page = req.params.page;%0A    let file = %22../../morteam-web/build/%22 + page + %22.js%22;%0A    // TODO: use the pacakge fs-promise%0A    fs.exists(file, function(exists) %7B%0A        if (!exists) %7B%0A            return res.end(%22fail%22); // AHHHH%0A        %7D%0A        fs.createReadStream(file).pipe(res);%0A    %7D);%0A%7D));%0A%0A
+    
 retu

Make the view work