From 8756180ad1b9f93e6993bcd01004d64891817c32 Mon Sep 17 00:00:00 2001 From: Alex Mikhalev Date: Mon, 3 Sep 2018 18:21:26 -0600 Subject: [PATCH] fix: icons generation, 404 errors, static serving --- client/webpack.config.js | 10 ++++++---- server/express/errorHandler.ts | 21 +++++++++++++++------ server/express/serveApp.ts | 3 ++- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/client/webpack.config.js b/client/webpack.config.js index e47a42f..b8e4315 100644 --- a/client/webpack.config.js +++ b/client/webpack.config.js @@ -32,7 +32,7 @@ function getConfig(env) { : isProd; // Get environment variables to inject into our app. const environ = getClientEnvironment(env, publicUrl); - + const postCssConfig = { loader: require.resolve("postcss-loader"), options: { @@ -170,9 +170,11 @@ function getConfig(env) { } : undefined }), - new FaviconsWebpackPlugin( - path.resolve(paths.clientDir, "images", "favicon-96x96.png") - ), + new FaviconsWebpackPlugin({ + logo: path.resolve(paths.clientDir, "images", "favicon-96x96.png"), + emitStatis: false, + prefix: "static/icons-[hash]/" + }), // Makes some environment variables available to the JS code, for example: // if (process.env.NODE_ENV === "production") { ... }. See `./env.js`. // It is absolutely essential that NODE_ENV was set to production here. diff --git a/server/express/errorHandler.ts b/server/express/errorHandler.ts index 7a8d55b..bed60f3 100644 --- a/server/express/errorHandler.ts +++ b/server/express/errorHandler.ts @@ -15,12 +15,21 @@ const errorHandler: express.ErrorRequestHandler = ( // TODO: different content-type? res.status(err.statusCode).json(err.toJSON(isDev)); } else if (err) { - const internalError = new ApiError( - "An internal server error has occurred", - ErrorCode.Internal, - err.stack ? err.stack : err - ); - errorHandler(internalError, req, res, next); + let error: ApiError; + if (err.code === "ENOENT") { + error = new ApiError( + "The specified resource could not be found", + ErrorCode.NotFound, + err + ); + } else { + error = new ApiError( + "An internal server error has occurred", + ErrorCode.Internal, + err.stack ? err.stack : err + ); + } + errorHandler(error, req, res, next); } next(); }; diff --git a/server/express/serveApp.ts b/server/express/serveApp.ts index 23d41c2..179f9e7 100644 --- a/server/express/serveApp.ts +++ b/server/express/serveApp.ts @@ -5,10 +5,11 @@ import * as serveStatic from "serve-static"; // tslint:disable-next-line:no-var-requires const paths = require("paths"); +const staticDir = path.resolve(paths.publicDir, "static"); const index = path.join(paths.publicDir, "index.html"); export default function serveApp(app: Express) { - app.use(serveStatic(paths.clientBuildDir)); + app.use("/static", serveStatic(staticDir, { fallthrough: false })); app.get("/*", (req, res) => { res.sendFile(index); });