Skip to content

Commit 944b7ab

Browse files
committed
Add a middleware
1 parent a7c42af commit 944b7ab

File tree

6 files changed

+34
-2
lines changed

6 files changed

+34
-2
lines changed

package-lock.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"babel-plugin-module-resolver": "^5.0.2",
2020
"babel-plugin-python": "^1.0.13",
2121
"babel-plugin-transform-commonjs": "https://github.com/soIu/babel-plugin-transform-commonjs/archive/refs/heads/master.tar.gz",
22+
"cookie": "^0.6.0",
2223
"expo": "~51.0.28",
2324
"expo-status-bar": "~1.12.1",
2425
"module-alias": "^2.2.3",

src/components/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { ServerBox } from './Box.js';
44
import { ServerProvider } from './ServerAction/Server.js';
55
import { ClientActionsConsumer } from './ServerAction/Client.js';
66
import AppExpo from '../../App.jsx';
7-
8-
console.log(AppExpo);
7+
import utils from '../utils';
98

109
const App = async ({ name }: { name: string }) => {
10+
console.log(utils.getRequest());
1111
return (
1212
<html>
1313
<head>

src/middleware/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import utils from '../utils';
2+
3+
const customMiddleware = () => {
4+
return async (ctx, next) => {
5+
utils.setCurrentRequest(ctx.req);
6+
await next();
7+
};
8+
};
9+
10+
export default customMiddleware;

src/utils/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const utils = {};
2+
3+
const context = {};
4+
5+
utils.setCurrentRequest = function (request) {
6+
context.currentRequest = request;
7+
}
8+
9+
utils.getRequest = () => context.currentRequest;
10+
11+
export default utils;

waku.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/** @type {import('waku/config').Config} */
22
export default {
33
middleware: () => [
4+
import('./src/middleware/index.js'),
45
import('waku/middleware/dev-server'),
56
import('waku/middleware/rsc'),
67
import('waku/middleware/fallback'),

0 commit comments

Comments
 (0)