[next] Templates (#1760)

* feat: initial support for synced tenants

* fix: cleanup

* fix: logger now respects logging level

* fix: cache now ignores updates issued from itself

* feat: print subscriber count

* feat: initial nunjucks support

* fix: support tenant cache for oidc strategy

* fix: replace some constructor initializers with property initializers

* fix: audit

* [next] Comments and Moderation (#1759)

* feat: initial moderation + validation for new comments

* fix: added Promiseable type

* feat: initial actions impl

* feat: more moderation phases

* fix: handle settings inheritence

* fix: moved settings into new file

* fix: defaults and documentation

* fix: replace merge with object spread

* feat: added integration with akismet

* fix: fixed compile

* fix: import ordering

* fix: merge issue causing build to fail

* feat: added gulp, static templates

* fix: added compile step back

* Fix extract css + remove cross-env
This commit is contained in:
Wyatt Johnson
2018-08-10 16:17:39 +00:00
committed by GitHub
parent 4e493ad1da
commit d2106b3de5
14 changed files with 1955 additions and 343 deletions
@@ -14,7 +14,6 @@ export interface SignupBody {
username: string;
password: string;
email: string;
displayName?: string;
}
const SignupBodySchema = Joi.object().keys({
@@ -0,0 +1,5 @@
import { RequestHandler } from "express";
export const streamHandler: RequestHandler = (req, res) => {
res.render("stream");
};
+39 -1
View File
@@ -1,7 +1,10 @@
import cons from "consolidate";
import { Express } from "express";
import http from "http";
import { Redis } from "ioredis";
import { Db } from "mongodb";
import nunjucks from "nunjucks";
import path from "path";
import { Config } from "talk-common/config";
import { notFoundMiddleware } from "talk-server/app/middleware/notFound";
@@ -29,6 +32,9 @@ export interface AppOptions {
* createApp will create a Talk Express app that can be used to handle requests.
*/
export async function createApp(options: AppOptions): Promise<Express> {
// Configure the application.
configureApplication(options);
// Pull the parent out of the options.
const { parent } = options;
@@ -46,7 +52,7 @@ export async function createApp(options: AppOptions): Promise<Express> {
);
// Static Files
parent.use(serveStatic);
parent.use("/assets", serveStatic);
// Error Handling
parent.use(notFoundMiddleware);
@@ -70,6 +76,38 @@ export const listenAndServe = (
const httpServer = app.listen(port, () => resolve(httpServer));
});
function configureApplication(options: AppOptions) {
const { parent } = options;
// Trust the first proxy in front of us, this will enable us to trust the fact
// that SSL was terminated correctly.
parent.set("trust proxy", 1);
// Setup the view config.
setupViews(options);
}
function setupViews(options: AppOptions) {
const { parent } = options;
// configure the default views directory.
const views = path.join(__dirname, "..", "..", "..", "static");
parent.set("views", views);
// Reconfigure nunjucks.
(cons.requires as any).nunjucks = nunjucks.configure(views, {
// In development, we should enable file watch mode.
watch: options.config.get("env") === "development",
});
// assign the nunjucks engine to .njk and .html files.
parent.engine("njk", cons.nunjucks);
parent.engine("html", cons.nunjucks);
// set .html as the default extension.
parent.set("view engine", "html");
}
/**
* attachSubscriptionHandlers attaches all the handlers to the http.Server to
* handle websocket traffic by upgrading their http connections to websocket.
@@ -1,5 +1,6 @@
import { RequestHandler } from "express";
export const notFoundMiddleware: RequestHandler = (req, res, next) => {
// FIXME: (wyattjoh) send an error that won't log as crazily as this one does.
next(new Error("not found"));
};
@@ -1,4 +1,8 @@
import serveStatic from "express-static-gzip";
import path from "path";
export default serveStatic(path.join(__dirname, "..", "..", "dist"), {});
const staticPath = path.resolve(
path.join(__dirname, "..", "..", "..", "..", "static", "assets")
);
export default serveStatic(staticPath, { index: false });
+3
View File
@@ -28,6 +28,9 @@ export default (options: MiddlewareOptions) => async (
// Attach the tenant to the request.
req.tenant = tenant;
// Attach the tenant to the view locals.
res.locals.tenant = tenant;
next();
} catch (err) {
next(err);
+4
View File
@@ -2,6 +2,7 @@ import express from "express";
import passport from "passport";
import { signupHandler } from "talk-server/app/handlers/auth/local";
import { streamHandler } from "talk-server/app/handlers/embed/stream";
import { apiErrorHandler } from "talk-server/app/middleware/error";
import { errorLogger } from "talk-server/app/middleware/logging";
import { wrapAuthn } from "talk-server/app/middleware/passport";
@@ -134,5 +135,8 @@ export async function createRouter(app: AppOptions, options: RouterOptions) {
);
}
// Handle the stream handler.
router.get("/embed/stream", streamHandler);
return router;
}