{ "files": { "bootstrap.js": { "content": "const { Framework } = require('@midwayjs/koa');\nconst { Bootstrap } = require('@midwayjs/bootstrap');\n\nconst web = new Framework().configure({\n port: 7001,\n});\n\nBootstrap.load(web)\n .run()\n .then(() => {\n console.log('Your application is running at http://localhost:7001');\n });\n" }, "index.html": { "content": "\n\n \n \n \n \n Vite App\n \n \n
\n \n \n\n" }, "jest.config.js": { "content": "module.exports = {\n preset: '@midwayjs/hooks',\n}\n" }, "midway.config.ts": { "content": "import { defineConfig } from '@midwayjs/hooks';\n\nexport default defineConfig({\n source: './src/apis',\n routes: [\n {\n baseDir: 'lambda',\n basePath: '/api',\n },\n ],\n});\n" }, "package.json": { "content": "{\n \"name\": \"midway-hooks-react\",\n \"version\": \"2.2.3\",\n \"private\": true,\n \"scripts\": {\n \"start\": \"node bootstrap\",\n \"dev\": \"vite\",\n \"build\": \"npm run build:client && npm run build:server\",\n \"build:client\": \"tsc && vite build\",\n \"build:server\": \"mw build\",\n \"serve\": \"vite preview\",\n \"test\": \"jest\"\n },\n \"dependencies\": {\n \"@midwayjs/hooks\": \"^2.2.2\",\n \"@midwayjs/koa\": \"^2.11.0\",\n \"koa-bodyparser\": \"^4.3.0\",\n \"react\": \"^17.0.0\",\n \"react-dom\": \"^17.0.0\"\n },\n \"devDependencies\": {\n \"@midwayjs/cli\": \"^1.2.71\",\n \"@midwayjs/cli-plugin-build\": \"^1.2.70\",\n \"@midwayjs/hooks-testing-library\": \"^2.2.2\",\n \"@midwayjs/vite-plugin-hooks\": \"^2.2.3\",\n \"@types/jest\": \"^26.0.23\",\n \"@types/koa-bodyparser\": \"^4.3.1\",\n \"@types/react\": \"^17.0.11\",\n \"@types/react-dom\": \"^17.0.7\",\n \"@vitejs/plugin-react-refresh\": \"^1.3.3\",\n \"jest\": \"^26.6.3\",\n \"typescript\": \"^4.2.4\",\n \"vite\": \"^2.3.7\"\n }\n}\n" }, "readme.md": { "content": "## Getting Started\n\nDocs:[Midway Hooks - Getting Started](https://www.yuque.com/midwayjs/midway_v2/hooks_intro?translate=en)\n\n### Directory Structure\n\n```\n.\n├── bootstrap.js //\n├── jest.config.js // Unit test file\n├── midway.config.ts // config file for setup directory and middleware\n├── src\n│   ├── apis // Backend directory\n│   │   ├── configuration.ts // Midway Hooks configuration\n│   │   └── lambda // Api directory(Can be modified in midway.config.ts)\n│   │   ├── index.test.ts // Api test file\n│   │   └── index.ts // Api file\n│   └── main.ts // Frontend framework file\n├── tsconfig.json\n└── vite.config.ts\n```\n\n### Commands\n\n#### Start Dev Server\n\n```bash\n$ npm run dev\n```\n\n#### Build\n\n```bash\n$ npm run build\n```\n\n### Running in production mode\n\n```bash\n$ node bootstrap.js\n```\n" }, "sandbox.config.json": { "content": "{\n \"infiniteLoopProtection\": true,\n \"hardReloadOnChange\": false,\n \"view\": \"browser\",\n \"template\": \"node\",\n \"container\": { \"port\": 3000, \"node\": \"14\" }\n}\n" }, "tsconfig.json": { "content": "{\n \"compilerOptions\": {\n \"target\": \"ESNext\",\n \"lib\": [\"DOM\", \"DOM.Iterable\", \"ESNext\"],\n \"allowJs\": false,\n \"esModuleInterop\": true,\n \"allowSyntheticDefaultImports\": true,\n \"strict\": false,\n \"skipLibCheck\": true,\n \"forceConsistentCasingInFileNames\": true,\n \"module\": \"ESNext\",\n \"moduleResolution\": \"Node\",\n \"resolveJsonModule\": true,\n \"noEmit\": true,\n \"jsx\": \"react\",\n \"experimentalDecorators\": true,\n \"emitDecoratorMetadata\": true,\n \"types\": [\"vite/client\", \"jest\"]\n },\n \"include\": [\"./src\"],\n \"ts-node\": {\n \"compilerOptions\": {\n \"module\": \"commonjs\"\n }\n }\n}\n" }, "vite.config.ts": { "content": "import { defineConfig } from 'vite';\nimport reactRefresh from '@vitejs/plugin-react-refresh';\nimport hooks from '@midwayjs/vite-plugin-hooks';\n\n// https://vitejs.dev/config/\nexport default defineConfig({\n plugins: [hooks(), reactRefresh()],\n});\n" }, "src/App.css": { "content": ".App {\n text-align: center;\n}\n\n.App-logo {\n height: 40vmin;\n pointer-events: none;\n}\n\n@media (prefers-reduced-motion: no-preference) {\n .App-logo {\n animation: App-logo-spin infinite 20s linear;\n }\n}\n\n.App-header {\n background-color: #282c34;\n min-height: 100vh;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n font-size: calc(10px + 2vmin);\n color: white;\n}\n\n.App-link {\n color: #61dafb;\n}\n\n@keyframes App-logo-spin {\n from {\n transform: rotate(0deg);\n }\n to {\n transform: rotate(360deg);\n }\n}\n\nbutton {\n font-size: calc(10px + 2vmin);\n}\n" }, "src/App.tsx": { "content": "import React, { useState, useEffect } from 'react';\nimport logo from './logo.svg';\nimport './App.css';\nimport hello, { post } from './apis/lambda';\n\nfunction App() {\n const [message, setMessage] = useState('');\n\n useEffect(() => {\n hello().then((response) => setMessage(response.message));\n }, []);\n\n const handleClick = async () => {\n const message = window.prompt('Type message!');\n const response = await post(message);\n alert(JSON.stringify(response, null, 2));\n };\n\n return (\n
\n
\n \"logo\"\n

Message from ./apis/lambda: {message}

\n

\n \n

\n

\n \n Learn Midway Hooks\n \n {' | '}\n \n React Docs\n \n {' | '}\n \n Vite Docs\n \n

\n
\n
\n );\n}\n\nexport default App;\n" }, "src/favicon.svg": { "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" }, "src/index.css": { "content": "body {\n margin: 0;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',\n 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',\n sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n}\n\ncode {\n font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',\n monospace;\n}\n" }, "src/logo.svg": { "content": "\n \n \n \n \n \n\n" }, "src/main.tsx": { "content": "import React from 'react';\nimport ReactDOM from 'react-dom';\nimport './index.css';\nimport App from './App';\n\nReactDOM.render(\n \n \n ,\n document.getElementById('root')\n);\n" }, "src/apis/configuration.ts": { "content": "import { hooks, createConfiguration } from '@midwayjs/hooks';\nimport bodyParser from 'koa-bodyparser';\n\nexport default createConfiguration({\n imports: [\n hooks({\n middleware: [bodyParser()],\n }),\n ],\n});\n" }, "src/apis/lambda/index.test.ts": { "content": "import { createApp, HooksApplication } from '@midwayjs/hooks-testing-library';\nimport api, { post } from '.';\n\ndescribe('test new features', () => {\n let app: HooksApplication;\n beforeAll(async () => {\n app = await createApp();\n });\n\n afterAll(async () => {\n await app.close();\n });\n\n it('runFunction', async () => {\n expect(await app.runFunction(api)).toMatchInlineSnapshot(`\n Object {\n \"message\": \"Hello World\",\n \"method\": \"GET\",\n }\n `);\n expect(await app.runFunction(post, 'Jake')).toMatchInlineSnapshot(`\n Object {\n \"method\": \"POST\",\n \"name\": \"Jake\",\n }\n `);\n });\n\n it('request', async () => {\n const response = await app.request(api).expect(200);\n expect(response.body).toMatchInlineSnapshot(`\n Object {\n \"message\": \"Hello World\",\n \"method\": \"GET\",\n }\n `);\n });\n});\n" }, "src/apis/lambda/index.ts": { "content": "import { useContext } from '@midwayjs/hooks';\nimport { Context } from '@midwayjs/koa';\n\nfunction useKoaContext() {\n return useContext();\n}\n\nexport default async () => {\n return {\n message: 'Hello World',\n method: useKoaContext().method,\n };\n};\n\nexport const post = async (name: string) => {\n return { method: 'POST', name };\n};\n" } } }