-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
66 lines (55 loc) · 2.14 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Feathers Example</title>
<link rel="stylesheet" href="//unpkg.com/[email protected]/public/base.css">
<link rel="stylesheet" href="//unpkg.com/[email protected]/public/chat.css">
</head>
<body>
<main id="main" class="container">
<h1>Sample feathers app with prisma</h1>
<form class="form" onsubmit="sendMessage(event.preventDefault())">
<input type="text" id="username" placeholder="username">
<input type="text" id="message-text" placeholder="Enter message here">
<button type="submit" class="button button-primary">Send message</button>
</form>
<h2>Here are the current messages:</h2>
</main>
<script src="//unpkg.com/@feathersjs/client@^4.3.0/dist/feathers.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.js"></script>
<script type="text/javascript">
// Set up socket.io
const socket = io('http://localhost:3030');
// Initialize a Feathers app
const app = feathers();
// Register socket.io to talk to our server
app.configure(feathers.socketio(socket));
// Form submission handler that sends a new message
async function sendMessage () {
const messageInput = document.getElementById('message-text');
const username = document.getElementById('username');
// Create a new message with the input field value
await app.service('messages').create({
text: messageInput.value,
username: username.value
});
messageInput.value = '';
username.value = '';
}
// Renders a single message on the page
function addMessage (message) {
document.getElementById('main').innerHTML += `<p> <b>${message.username}:</b> ${message.content}</p>`;
}
const main = async () => {
// Find all existing messages
const messages = await app.service('messages').find();
// Add existing messages to the list
messages.forEach(addMessage);
// Add any newly created message to the list in real-time
app.service('messages').on('created', addMessage);
};
main();
</script>
</body>
</html>