-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SDPA-3045] Added request id in all route requests (#500)
* Added request id in all route requests
- Loading branch information
Showing
14 changed files
with
222 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/ripple-nuxt-tide/lib/server-middleware/request-id.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Log server connection | ||
import { generateId } from './../core/tide-helper' | ||
const url = require('url') | ||
|
||
module.exports = function (req, res, next) { | ||
// req is the Node.js http request object | ||
const reqUrl = decodeURI((url.parse(req.url)).pathname) | ||
if (!reqUrl.includes('/api/v')) { | ||
req.requestId = generateId() | ||
} | ||
// next is a function to call to invoke the next middleware | ||
// Don't forget to call next at the end if your middleware is not an endpoint! | ||
next() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { generateId } from '@dpc-sdp/ripple-nuxt-tide/lib/core/tide-helper' | ||
import middleware from './middleware' | ||
|
||
middleware['request-id'] = async (context) => { | ||
const { req, route, isHMR } = context; | ||
|
||
if (isHMR) { | ||
return | ||
} | ||
|
||
// Set request id for all Tide requests within the same route | ||
if (req && req.requestId) { | ||
// Nuxt req is server only variable, we pass the server request id to here. | ||
route.requestId = req.requestId | ||
} else { | ||
// Generate a request id if it's a client side navigation. | ||
route.requestId = generateId() | ||
} | ||
} |
Oops, something went wrong.