Browse Source

Added request logger and made stuff better

update-deps
Alex Mikhalev 7 years ago
parent
commit
a698775388
  1. 5
      app/webpack.config.js
  2. 7
      package.json
  3. 3
      paths.js
  4. 2
      server/app/index.ts
  5. 8
      server/app/logger.ts
  6. 25
      server/app/serveApp.ts
  7. 6
      server/configureAlias.ts
  8. 6
      server/configureLogger.ts
  9. 7
      server/express-pino-logger.d.ts
  10. 12
      server/index.ts
  11. 69
      yarn.lock

5
app/webpack.config.js

@ -229,6 +229,11 @@ const getConfig = module.exports = (env) => {
plugins: plugins, plugins: plugins,
devServer: { devServer: {
hot: true, hot: true,
port: 8081,
proxy: [{
context: ["/api"], // TODO: update when there is actually an api
target: paths.publicUrl,
}],
}, },
} }
}; };

7
package.json

@ -41,12 +41,12 @@
"@types/react-dom": "^15.5.0", "@types/react-dom": "^15.5.0",
"@types/react-fontawesome": "^1.5.0", "@types/react-fontawesome": "^1.5.0",
"@types/react-hot-loader": "^3.0.4", "@types/react-hot-loader": "^3.0.4",
"@types/webpack-hot-middleware": "^2.16.0",
"autoprefixer": "^7.1.4", "autoprefixer": "^7.1.4",
"case-sensitive-paths-webpack-plugin": "^2.1.1", "case-sensitive-paths-webpack-plugin": "^2.1.1",
"classnames": "^2.2.5", "classnames": "^2.2.5",
"dotenv": "^4.0.0", "dotenv": "^4.0.0",
"express": "^4.15.4", "express": "^4.15.4",
"express-pino-logger": "^2.0.0",
"extract-text-webpack-plugin": "^3.0.0", "extract-text-webpack-plugin": "^3.0.0",
"font-awesome": "^4.7.0", "font-awesome": "^4.7.0",
"mobx": "^3.1.11", "mobx": "^3.1.11",
@ -67,11 +67,9 @@
"semantic-ui-react": "^0.73.0", "semantic-ui-react": "^0.73.0",
"tslint-loader": "^3.5.3", "tslint-loader": "^3.5.3",
"uglifyjs-webpack-plugin": "^0.4.6", "uglifyjs-webpack-plugin": "^0.4.6",
"url-loader": "^0.5.9", "url-loader": "^0.5.9"
"webpack-hot-middleware": "^2.19.1"
}, },
"devDependencies": { "devDependencies": {
"@types/webpack-dev-middleware": "^1.9.3",
"@types/webpack-env": "^1.13.0", "@types/webpack-env": "^1.13.0",
"awesome-typescript-loader": "^3.1.3", "awesome-typescript-loader": "^3.1.3",
"css-loader": "^0.28.4", "css-loader": "^0.28.4",
@ -87,7 +85,6 @@
"tslint-react": "^3.2.0", "tslint-react": "^3.2.0",
"typescript": "^2.3.4", "typescript": "^2.3.4",
"webpack": "^3.0.0", "webpack": "^3.0.0",
"webpack-dev-middleware": "^1.12.0",
"webpack-dev-server": "^2.4.4" "webpack-dev-server": "^2.4.4"
} }
} }

3
paths.js

@ -20,7 +20,7 @@ function ensureSlash(path, needsSlash) {
exports.dotenv = resolveRoot(".env"); exports.dotenv = resolveRoot(".env");
exports.nodeModulesDir = resolveRoot("node_modules"); exports.nodeModulesDir = resolveRoot("node_modules");
exports.packageJson = resolveRoot("package.json"); exports.packageJson = resolveRoot("package.json");
exports.publicUrl = ensureSlash(process.env.PUBLIC_URL || "/", true); exports.publicUrl = ensureSlash(process.env.PUBLIC_URL || "http://localhost:8080/", true);
exports.publicPath = ensureSlash(url.parse(exports.publicUrl).pathname || "/", true); exports.publicPath = ensureSlash(url.parse(exports.publicUrl).pathname || "/", true);
exports.commonDir = resolveRoot("common"); exports.commonDir = resolveRoot("common");
@ -31,6 +31,7 @@ exports.appHtml = path.resolve(exports.appDir, "index.html");
exports.appWebpackConfig = path.resolve(exports.appDir, "webpack.config.js"); exports.appWebpackConfig = path.resolve(exports.appDir, "webpack.config.js");
exports.appTsConfig = path.resolve(exports.appDir, "tsconfig.json"); exports.appTsConfig = path.resolve(exports.appDir, "tsconfig.json");
exports.appBuildDir = resolveRoot("public"); exports.appBuildDir = resolveRoot("public");
exports.publicDir = exports.appBuildDir;
exports.serverDir = resolveRoot("server"); exports.serverDir = resolveRoot("server");
exports.serverBuildDir = resolveRoot("dist"); exports.serverBuildDir = resolveRoot("dist");

2
server/app/index.ts

@ -1,9 +1,11 @@
import * as express from "express"; import * as express from "express";
import logger from "./logger";
import serveApp from "./serveApp"; import serveApp from "./serveApp";
const app = express(); const app = express();
app.use(logger);
serveApp(app); serveApp(app);
export default app; export default app;

8
server/app/logger.ts

@ -0,0 +1,8 @@
import log from "@common/logger";
import expressPinoLogger = require("express-pino-logger");
import * as pino from "pino";
const l = pino();
pino(l);
export default expressPinoLogger(log);

25
server/app/serveApp.ts

@ -1,28 +1,9 @@
import { Express } from "express"; import { Express } from "express";
import * as paths from "paths"; import * as serveStatic from "serve-static";
import * as webpack from "webpack";
import * as webpackMiddleware from "webpack-dev-middleware";
import * as webpackHotMiddleware from "webpack-hot-middleware";
import logger from "@common/logger"; import logger from "@common/logger";
const log = logger.child({ source: "webpack" }); import * as paths from "paths";
/* tslint:disable-next-line:no-var-requires */
const webpackConfig = require(paths.appWebpackConfig)("dev");
export default function serveApp(app: Express) { export default function serveApp(app: Express) {
const compiler = webpack(webpackConfig); app.use(serveStatic(paths.appBuildDir));
app.use(webpackMiddleware(compiler,
{
noInfo: true,
publicPath: webpackConfig.output.publicPath,
log: log.info.bind(log),
warn: log.warn.bind(log),
error: log.error.bind(log),
},
));
app.use(webpackHotMiddleware(compiler,
{
log: log.info.bind(log),
}));
} }

6
server/configureAlias.ts

@ -0,0 +1,6 @@
import * as moduleAlias from "module-alias";
import * as path from "path";
moduleAlias.addAlias("@common", path.resolve(__dirname, "..", "common"));
moduleAlias.addAlias("@server", __dirname);
moduleAlias.addAlias("env", require.resolve("../env"));
moduleAlias.addAlias("paths", require.resolve("../paths"));

6
server/configureLogger.ts

@ -0,0 +1,6 @@
import log, { setLogger } from "@common/logger";
setLogger(log.child({
name: "sprinklers3/server",
level: "trace",
}));

7
server/express-pino-logger.d.ts vendored

@ -0,0 +1,7 @@
declare module "express-pino-logger" {
import { Logger } from "pino";
import { ErrorRequestHandler } from "express";
function makeLogger(logger: Logger): ErrorRequestHandler;
export = makeLogger;
}

12
server/index.ts

@ -1,16 +1,12 @@
import * as moduleAlias from "module-alias"; import "./configureAlias";
import * as path from "path";
moduleAlias.addAlias("@common", path.resolve(__dirname, "..", "common"));
moduleAlias.addAlias("@server", __dirname);
moduleAlias.addAlias("paths", require.resolve("../paths"));
import log, { setLogger } from "@common/logger"; import "env";
import log from "@common/logger";
import * as mqtt from "@common/mqtt"; import * as mqtt from "@common/mqtt";
import { Server } from "http"; import { Server } from "http";
import app from "./app"; import app from "./app";
setLogger(log.child({ name: "sprinklers3/server", level: "trace" }));
const mqttClient = new mqtt.MqttApiClient("mqtt://localhost:1882"); const mqttClient = new mqtt.MqttApiClient("mqtt://localhost:1882");
mqttClient.start(); mqttClient.start();

69
yarn.lock

@ -10,12 +10,6 @@
version "2.2.3" version "2.2.3"
resolved "https://registry.yarnpkg.com/@types/classnames/-/classnames-2.2.3.tgz#3f0ff6873da793870e20a260cada55982f38a9e5" resolved "https://registry.yarnpkg.com/@types/classnames/-/classnames-2.2.3.tgz#3f0ff6873da793870e20a260cada55982f38a9e5"
"@types/connect@*":
version "3.4.31"
resolved "https://registry.yarnpkg.com/@types/connect/-/connect-3.4.31.tgz#1f92d6b117ecc05076c49ecd024f7976e528bad9"
dependencies:
"@types/node" "*"
"@types/core-js@^0.9.43": "@types/core-js@^0.9.43":
version "0.9.43" version "0.9.43"
resolved "https://registry.yarnpkg.com/@types/core-js/-/core-js-0.9.43.tgz#65d646c5e8c0cd1bdee37065799f9d3d48748253" resolved "https://registry.yarnpkg.com/@types/core-js/-/core-js-0.9.43.tgz#65d646c5e8c0cd1bdee37065799f9d3d48748253"
@ -94,46 +88,10 @@
"@types/express-serve-static-core" "*" "@types/express-serve-static-core" "*"
"@types/mime" "*" "@types/mime" "*"
"@types/source-map@*":
version "0.5.1"
resolved "https://registry.yarnpkg.com/@types/source-map/-/source-map-0.5.1.tgz#7e74db5d06ab373a712356eebfaea2fad0ea2367"
"@types/tapable@*":
version "0.2.4"
resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-0.2.4.tgz#8181a228da46185439300e600c5ae3b3b3982585"
"@types/uglify-js@*":
version "2.6.29"
resolved "https://registry.yarnpkg.com/@types/uglify-js/-/uglify-js-2.6.29.tgz#521347f69e20201d218f5991ae66e10878afcf1a"
dependencies:
"@types/source-map" "*"
"@types/webpack-dev-middleware@^1.9.3":
version "1.9.3"
resolved "https://registry.yarnpkg.com/@types/webpack-dev-middleware/-/webpack-dev-middleware-1.9.3.tgz#2120f79a4fbb0dc49ddba97e4b0b778f947c7c5b"
dependencies:
"@types/connect" "*"
"@types/webpack" "*"
"@types/webpack-env@^1.13.0": "@types/webpack-env@^1.13.0":
version "1.13.1" version "1.13.1"
resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.13.1.tgz#b45c222e24301bd006e3edfc762cc6b51bda236a" resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.13.1.tgz#b45c222e24301bd006e3edfc762cc6b51bda236a"
"@types/webpack-hot-middleware@^2.16.0":
version "2.16.0"
resolved "https://registry.yarnpkg.com/@types/webpack-hot-middleware/-/webpack-hot-middleware-2.16.0.tgz#4fe6b0bc077b43d4341c0c5b212d9198ab8b79a3"
dependencies:
"@types/connect" "*"
"@types/webpack" "*"
"@types/webpack@*":
version "3.0.10"
resolved "https://registry.yarnpkg.com/@types/webpack/-/webpack-3.0.10.tgz#1d27db07df32109f8c882535b547aae4252fd53e"
dependencies:
"@types/node" "*"
"@types/tapable" "*"
"@types/uglify-js" "*"
abbrev@1: abbrev@1:
version "1.1.0" version "1.1.0"
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.0.tgz#d0554c2256636e2f56e7c2e5ad183f859428d81f" resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.0.tgz#d0554c2256636e2f56e7c2e5ad183f859428d81f"
@ -1693,6 +1651,12 @@ expand-tilde@^2.0.0, expand-tilde@^2.0.2:
dependencies: dependencies:
homedir-polyfill "^1.0.1" homedir-polyfill "^1.0.1"
express-pino-logger@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/express-pino-logger/-/express-pino-logger-2.0.0.tgz#e2b1046a8e9a9fe65d4e7fcbe57115e28df076a1"
dependencies:
pino-http "^2.0.0"
express@^4.13.3, express@^4.15.4: express@^4.13.3, express@^4.15.4:
version "4.15.4" version "4.15.4"
resolved "https://registry.yarnpkg.com/express/-/express-4.15.4.tgz#032e2253489cf8fce02666beca3d11ed7a2daed1" resolved "https://registry.yarnpkg.com/express/-/express-4.15.4.tgz#032e2253489cf8fce02666beca3d11ed7a2daed1"
@ -3574,7 +3538,13 @@ pinkie@^2.0.0:
version "2.0.4" version "2.0.4"
resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870" resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870"
pino@^4.7.2: pino-http@^2.0.0:
version "2.6.2"
resolved "https://registry.yarnpkg.com/pino-http/-/pino-http-2.6.2.tgz#aedb71b08d15bc69d959870bafa6b7780103274f"
dependencies:
pino "^4.0.2"
pino@^4.0.2, pino@^4.7.2:
version "4.7.2" version "4.7.2"
resolved "https://registry.yarnpkg.com/pino/-/pino-4.7.2.tgz#56e8e712637669095f0a61b27a15649d62dec8cd" resolved "https://registry.yarnpkg.com/pino/-/pino-4.7.2.tgz#56e8e712637669095f0a61b27a15649d62dec8cd"
dependencies: dependencies:
@ -4021,7 +3991,7 @@ querystring-es3@^0.2.0:
version "0.2.1" version "0.2.1"
resolved "https://registry.yarnpkg.com/querystring-es3/-/querystring-es3-0.2.1.tgz#9ec61f79049875707d69414596fd907a4d711e73" resolved "https://registry.yarnpkg.com/querystring-es3/-/querystring-es3-0.2.1.tgz#9ec61f79049875707d69414596fd907a4d711e73"
querystring@0.2.0, querystring@^0.2.0: querystring@0.2.0:
version "0.2.0" version "0.2.0"
resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.0.tgz#b209849203bb25df820da756e747005878521620" resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.0.tgz#b209849203bb25df820da756e747005878521620"
@ -5337,7 +5307,7 @@ wbuf@^1.1.0, wbuf@^1.7.2:
dependencies: dependencies:
minimalistic-assert "^1.0.0" minimalistic-assert "^1.0.0"
webpack-dev-middleware@^1.11.0, webpack-dev-middleware@^1.12.0: webpack-dev-middleware@^1.11.0:
version "1.12.0" version "1.12.0"
resolved "https://registry.yarnpkg.com/webpack-dev-middleware/-/webpack-dev-middleware-1.12.0.tgz#d34efefb2edda7e1d3b5dbe07289513219651709" resolved "https://registry.yarnpkg.com/webpack-dev-middleware/-/webpack-dev-middleware-1.12.0.tgz#d34efefb2edda7e1d3b5dbe07289513219651709"
dependencies: dependencies:
@ -5376,15 +5346,6 @@ webpack-dev-server@^2.4.4:
webpack-dev-middleware "^1.11.0" webpack-dev-middleware "^1.11.0"
yargs "^6.6.0" yargs "^6.6.0"
webpack-hot-middleware@^2.19.1:
version "2.19.1"
resolved "https://registry.yarnpkg.com/webpack-hot-middleware/-/webpack-hot-middleware-2.19.1.tgz#5db32c31c955c1ead114d37c7519ea554da0d405"
dependencies:
ansi-html "0.0.7"
html-entities "^1.2.0"
querystring "^0.2.0"
strip-ansi "^3.0.0"
webpack-sources@^1.0.1: webpack-sources@^1.0.1:
version "1.0.1" version "1.0.1"
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.0.1.tgz#c7356436a4d13123be2e2426a05d1dad9cbe65cf" resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.0.1.tgz#c7356436a4d13123be2e2426a05d1dad9cbe65cf"

Loading…
Cancel
Save