Browse Source

fix: icons generation, 404 errors, static serving

update-deps
Alex Mikhalev 6 years ago
parent
commit
8756180ad1
  1. 8
      client/webpack.config.js
  2. 21
      server/express/errorHandler.ts
  3. 3
      server/express/serveApp.ts

8
client/webpack.config.js

@ -170,9 +170,11 @@ function getConfig(env) {
} }
: undefined : undefined
}), }),
new FaviconsWebpackPlugin( new FaviconsWebpackPlugin({
path.resolve(paths.clientDir, "images", "favicon-96x96.png") 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: // Makes some environment variables available to the JS code, for example:
// if (process.env.NODE_ENV === "production") { ... }. See `./env.js`. // if (process.env.NODE_ENV === "production") { ... }. See `./env.js`.
// It is absolutely essential that NODE_ENV was set to production here. // It is absolutely essential that NODE_ENV was set to production here.

21
server/express/errorHandler.ts

@ -15,12 +15,21 @@ const errorHandler: express.ErrorRequestHandler = (
// TODO: different content-type? // TODO: different content-type?
res.status(err.statusCode).json(err.toJSON(isDev)); res.status(err.statusCode).json(err.toJSON(isDev));
} else if (err) { } else if (err) {
const internalError = new ApiError( let error: ApiError;
"An internal server error has occurred", if (err.code === "ENOENT") {
ErrorCode.Internal, error = new ApiError(
err.stack ? err.stack : err "The specified resource could not be found",
); ErrorCode.NotFound,
errorHandler(internalError, req, res, next); err
);
} else {
error = new ApiError(
"An internal server error has occurred",
ErrorCode.Internal,
err.stack ? err.stack : err
);
}
errorHandler(error, req, res, next);
} }
next(); next();
}; };

3
server/express/serveApp.ts

@ -5,10 +5,11 @@ import * as serveStatic from "serve-static";
// tslint:disable-next-line:no-var-requires // tslint:disable-next-line:no-var-requires
const paths = require("paths"); const paths = require("paths");
const staticDir = path.resolve(paths.publicDir, "static");
const index = path.join(paths.publicDir, "index.html"); const index = path.join(paths.publicDir, "index.html");
export default function serveApp(app: Express) { export default function serveApp(app: Express) {
app.use(serveStatic(paths.clientBuildDir)); app.use("/static", serveStatic(staticDir, { fallthrough: false }));
app.get("/*", (req, res) => { app.get("/*", (req, res) => {
res.sendFile(index); res.sendFile(index);
}); });

Loading…
Cancel
Save