-
Notifications
You must be signed in to change notification settings - Fork 0
netlify changes #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@splindsay-92 Hey Steven... managed to commit myself :) This works with Netlify, but my code etiquette may be a bit crap. Also still working on the readme. would be great if you could review in the meanwhile |
components/Chat.jsx
Outdated
|
|
||
| export default function Chat() { | ||
| const realtimeClient = new Ably.Realtime({ authUrl: '/api' }); | ||
| const realtimeClient = new Ably.Realtime({ authUrl: 'http://localhost:8888/.netlify/functions/auth' }); // make sure this matches your localhost server |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to get this to work with a relative path. open to suggestions @splindsay-92 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the error it was giving you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if I set authUrl to .netlify/functions/auth:
Ably: Auth.requestToken(): token request signing call returned error; err = TypeError: Invalid URL
GET / 200 in 1298ms
Request from ::1: GET /.netlify/functions/auth?rnd=9905685111520733
Response with status 200 in 65 ms.
if I set authUrl to /.netlify/functions/auth:
13:01:40.149 Ably: Auth.requestToken(): token request signing call returned error; err = Error: `input` must not start with a slash when using `prefixUrl`
GET / 200 in 1338ms
Request from ::1: GET /.netlify/functions/auth?rnd=1762475061762131
Response with status 200 in 44 ms.
if I set authUrl to ${window.location.origin}/.netlify/functions/auth (to try to bypass prefixUrl error), I get the same error as above.
fixing chat import
|
draft of the actual article is here: https://ghost.ably.com/ghost/#/editor/post/681b53d118da650028141ff2 |
removing room reactions line
small fixes
fixing sendMessage
make pretty
| @@ -0,0 +1,6 @@ | |||
| [build] | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there are no redirects here, probably why your API call didn't work correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also the adapter plugin, but can't see this in your packages file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry what adapter plugin?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one netlify/plugin-nextjs :)
components/ChatBox.jsx
Outdated
| }); | ||
|
|
||
| const sendChatMessage = async (text) => { | ||
| if (!sendMessage) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will always be truthy, send is actually a promise, so the check can be removed.
netlify/functions/auth.js
Outdated
| const client = new Ably.Rest(process.env.ABLY_API_KEY); | ||
| const tokenRequest = await client.auth.createTokenRequest({ | ||
| clientId: "ably-chat-demo", | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you're also missing the capability definitions here
const tokenRequestData = await client.auth.createTokenRequest({
capability: {
'[chat]*': ['*'],
'*': ['*'],
},
clientId: clientId,
});
Also, the clientId should really be passed to this handler in the GET call and not defined here. The above will work, but its not really correct and would be an anti-pattern.
- Major overhaul to use ts. - Correctly redirect to auth function, it now accepts a clientId and adds chat capabilities - Added tool version file with nodejs dep. - Added next.ts config. - Updated package.json - Updated eslint - Updated README.md - Randomly generate clientIds on render
…l-overhaul Refactor: Refactor to use ts and netlify functions
No description provided.