Skip to content

Commit

Permalink
feat(logginig): unify query logging
Browse files Browse the repository at this point in the history
  • Loading branch information
wzr1337 committed Jan 11, 2017
1 parent bb17c6c commit 0ebf137
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/expressapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class WebServer {
this.app = express();
this.app.use(bodyParser.json());
this.app.use(bodyParser.urlencoded({ extended: false }));
this.app.use((req:express.Request, res:express.Response, next:express.NextFunction)=>{
console.log("Query:", req.method, req.url);
next();
})

// Get port from environment and store in Express.
this._port = this.normalizePort(process.env.PORT || _port || '3000');
Expand Down
5 changes: 0 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ fs.readdir(path.join(__dirname, "plugins"), (err:NodeJS.ErrnoException, files: s
const elementGET = (service:Service, resource:Resource) => {
let elementPath = pathof(service, resource) + "/:id"
return (req: express.Request, res: express.Response, next: express.NextFunction) => {
console.log("Query: GET", req.path);

if(!resource.getElement) {
res.status(501).send("Not Implemented");
Expand Down Expand Up @@ -76,7 +75,6 @@ const resourceGET = (service:Service, resource:Resource) => {
let resourcePath = pathof(service, resource);
console.log("GET", resourcePath, "registered");
return (req: express.Request, res: express.Response, next: express.NextFunction) => {
console.log("Query: GET", req.path);
if(!resource.getResource) {
res.status(501).send("Not Implemented");
return;
Expand Down Expand Up @@ -109,7 +107,6 @@ const resourcePOST = (service:Service, resource:Resource) => {
let resourcePath = pathof(service, resource);
console.log("POST", resourcePath, "registered");
return (req: express.Request, res: express.Response, next: express.NextFunction) => {
console.log("Query: POST", req.path);
if(!resource.createElement) {
res.status(501).send("Not Implemented");
return;
Expand All @@ -121,7 +118,6 @@ const elementDELETE = (service:Service, resource:Resource) => {
let elementPath = pathof(service, resource) + "/:id"
console.log("DELETE", elementPath, "registered");
return (req: express.Request, res: express.Response, next: express.NextFunction) => {
console.log("Query: DELETE", req.path);

if(!resource.deleteElement) {
res.status(501).send("Not Implemented");
Expand Down Expand Up @@ -149,7 +145,6 @@ const elementPOST = (service:Service, resource:Resource) => {
let elementPath = pathof(service, resource) + "/:id"
console.log("POST", elementPath, "registered");
return (req: express.Request, res: express.Response, next: express.NextFunction) => {
console.log("Query: POST", req.path);

// find the element requested by the client
let element = resource.getElement(req.params.id);
Expand Down

0 comments on commit 0ebf137

Please sign in to comment.