-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Raymond Ottun
committed
Nov 15, 2021
1 parent
25e2dd8
commit 3978734
Showing
18 changed files
with
181 additions
and
16 deletions.
There are no files selected for viewing
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"request": { | ||
"path": "/api/weather", | ||
"method": "GET" | ||
}, | ||
"response": { | ||
"statusCode": 200, | ||
"body": { | ||
"coord": { | ||
"lon": -122.08, | ||
"lat": 37.39 | ||
}, | ||
"weather": [ | ||
{ | ||
"id": 800, | ||
"main": "Clear", | ||
"description": "clear sky", | ||
"icon": "01d" | ||
} | ||
], | ||
"base": "stations", | ||
"main": { | ||
"temp": 282.55, | ||
"feels_like": 281.86, | ||
"temp_min": 280.37, | ||
"temp_max": 284.26, | ||
"pressure": 1023, | ||
"humidity": 100 | ||
}, | ||
"visibility": 16093, | ||
"wind": { | ||
"speed": 1.5, | ||
"deg": 350 | ||
}, | ||
"clouds": { | ||
"all": 1 | ||
}, | ||
"dt": 1560350645, | ||
"sys": { | ||
"type": 1, | ||
"id": 5122, | ||
"message": 0.0139, | ||
"country": "US", | ||
"sunrise": 1560343627, | ||
"sunset": 1560396563 | ||
}, | ||
"timezone": -25200, | ||
"id": 420006353, | ||
"name": "Mountain View", | ||
"cod": 200 | ||
} | ||
} | ||
} |
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,6 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/types/global" /> | ||
/// <reference types="next/image-types/global" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/basic-features/typescript for more information. |
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,18 @@ | ||
{ | ||
"name": "deputy-with-express-middleware", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"dev": "next dev" | ||
}, | ||
"dependencies": { | ||
"@sayjava/deputy": "../../", | ||
"next": "^12.0.3", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^17.0.34" | ||
} | ||
} |
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,15 @@ | ||
import { createExpressMiddleware } from '@sayjava/deputy'; | ||
|
||
const mockMiddleware = createExpressMiddleware({ mocksDirectory: 'mocks' }); | ||
const callRemoteApi = (req, res) => { | ||
console.log('Call some remote api'); | ||
res.send('result from remote api'); | ||
}; | ||
|
||
export default (req, res) => { | ||
if (process.env.NODE_ENV !== 'production') { | ||
return mockMiddleware(req, res); | ||
} | ||
|
||
return callRemoteApi(req, res); | ||
}; |
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,42 @@ | ||
import {useEffect, useState} from 'react' | ||
export default () => { | ||
const [state, setState] = useState(null) | ||
|
||
useEffect(() => { | ||
fetch('/api/weather') | ||
.then(res => res.json()) | ||
.then(data => setState({error: null, data})) | ||
.catch(error => setState({error, data: null})) | ||
}, []) | ||
|
||
|
||
if(!state) { | ||
return <div> | ||
Loading up weather | ||
</div> | ||
} | ||
|
||
if(state.error) { | ||
return <div style={{color: 'red'}}> | ||
{state.error.message} | ||
</div> | ||
} | ||
|
||
console.log(state.data) | ||
|
||
return <div> | ||
<h2>{state.data.name}'s Weather</h2> | ||
<div> | ||
<h4>Feels Like</h4> | ||
<ul> | ||
<li>{state.data.main.feels_like}</li> | ||
<li>{state.data.main.humidity}</li> | ||
</ul> | ||
<h4>Weather</h4> | ||
<ul> | ||
<li>{state.data.weather[0].description}</li> | ||
<li>{state.data.weather[0].main}</li> | ||
</ul> | ||
</div> | ||
</div> | ||
} |
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,30 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"lib": [ | ||
"dom", | ||
"dom.iterable", | ||
"esnext" | ||
], | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": false, | ||
"forceConsistentCasingInFileNames": true, | ||
"noEmit": true, | ||
"incremental": true, | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"jsx": "preserve" | ||
}, | ||
"include": [ | ||
"next-env.d.ts", | ||
"**/*.ts", | ||
"**/*.tsx" | ||
], | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
export const createExpressMiddleware = () => console.info('Coming soon'); | ||
import { createMiddleware } from './server'; | ||
import { MiddlewareConfig } from './types'; | ||
export const createExpressMiddleware = (config: MiddlewareConfig) => createMiddleware(config); |
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