forked from webrpc/webrpc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update node-ts example with an empty response type (webrpc#131)
This proves webrpc#74 is not caused by TypeScript generator
- Loading branch information
1 parent
3f15b9f
commit 22c3a14
Showing
8 changed files
with
91 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"trailingComma": "es5", | ||
"tabWidth": 2, | ||
"semi": false, | ||
"singleQuote": true, | ||
"useTabs": true | ||
} |
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,42 +1,40 @@ | ||
import express from 'express' | ||
import { createExampleServiceApp } from './server.gen' | ||
import * as proto from './server.gen' | ||
import { createExampleServiceApp } from './server.gen' | ||
|
||
const app = express() | ||
|
||
app.use((req, res, next) => { | ||
res.setHeader('Access-Control-Allow-Origin', '*') | ||
res.setHeader('Access-Control-Allow-Methods', 'POST, GET, OPTIONS') | ||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type') | ||
res.setHeader('Access-Control-Allow-Origin', '*') | ||
res.setHeader('Access-Control-Allow-Methods', 'POST, GET, OPTIONS') | ||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type') | ||
|
||
if (req.method === 'OPTIONS') { | ||
res.status(200).end() | ||
return | ||
} | ||
if (req.method === 'OPTIONS') { | ||
res.status(200).end() | ||
return | ||
} | ||
|
||
next() | ||
}); | ||
next() | ||
}) | ||
|
||
const exampleServiceApp = createExampleServiceApp({ | ||
Ping: () => { | ||
return { | ||
status: false | ||
} | ||
}, | ||
|
||
GetUser: () => ({ | ||
code: 1, | ||
user: { | ||
id: 1, | ||
USERNAME: 'webrpcfan', | ||
role: proto.Kind.ADMIN, | ||
meta: {} | ||
} | ||
}) | ||
Ping: () => { | ||
return {} | ||
}, | ||
|
||
GetUser: () => ({ | ||
code: 1, | ||
user: { | ||
id: 1, | ||
USERNAME: 'webrpcfan', | ||
role: proto.Kind.ADMIN, | ||
meta: {}, | ||
}, | ||
}), | ||
}) | ||
|
||
app.use(exampleServiceApp) | ||
|
||
app.listen(3000, () => { | ||
console.log('> Listening on port 3000'); | ||
console.log('> Listening on port 3000') | ||
}) |
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
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 |
---|---|---|
@@ -1,26 +1,54 @@ | ||
import { ExampleService } from './client.gen' | ||
|
||
const exampleService = new ExampleService( | ||
'http://localhost:3000', | ||
(input, init) => fetch(input, init) | ||
'http://localhost:3000', | ||
(input, init) => fetch(input, init) | ||
) | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
const userContainer = document.getElementsByClassName('js-user')[0] | ||
const loadUserButton = document.getElementsByClassName('js-load-user-btn')[0] | ||
const userNameText = document.getElementsByClassName('js-username')[0] | ||
const pingButton = document.getElementById('js-ping-btn') | ||
const pingText = document.getElementById('js-ping-text') | ||
|
||
loadUserButton.addEventListener('click', () => { | ||
exampleService | ||
.getUser({ | ||
userID: 1 | ||
}) | ||
.then(({ user }) => { | ||
console.log('getUser() responded with:', {user}) | ||
if (!pingButton || !pingText) { | ||
console.log('error getting ping HTML elements') | ||
return | ||
} | ||
|
||
userContainer.classList.add('loaded') | ||
pingButton.addEventListener('click', () => { | ||
exampleService | ||
.ping({}) | ||
.then(({}) => { | ||
console.log('ping() responded:', {}) | ||
pingText.textContent = 'PONG' | ||
}) | ||
.catch((e) => { | ||
console.log('ping() failed:', e) | ||
pingText.textContent = 'ping() failed: ' + e.message | ||
}) | ||
}) | ||
}) | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
const getUserButton = document.getElementById('js-get-user-btn') | ||
const usernameText = document.getElementById('js-username-text') | ||
|
||
if (!getUserButton || !usernameText) { | ||
console.log('error getting username HTML elements') | ||
return | ||
} | ||
|
||
userNameText.textContent = user.USERNAME | ||
}) | ||
}) | ||
getUserButton.addEventListener('click', () => { | ||
exampleService | ||
.getUser({ | ||
userID: 1, | ||
}) | ||
.then(({ user }) => { | ||
console.log('getUser() responded with:', { user }) | ||
usernameText.textContent = user.USERNAME | ||
}) | ||
.catch((e) => { | ||
console.log('getUser() failed:', e) | ||
usernameText.textContent = 'getUser() failed: ' + e.message | ||
}) | ||
}) | ||
}) |