How to use horizon io with express Node js?
victorosario opened this issue · 0 comments
victorosario commented
I am new to rethinkidb and horizon.I just wanna do React app Which use node js and horizon io.This is my First attempt setup this.And I have No idea How to do this.Thanks in advance.There No Error is coming from this code.But this code should store the value Its not working.
server.js
import express from 'express';
import horizon from '@horizon/server'
const app = express();
const httpServer = app.listen(8181,() => {
console.log('I an At 3000')
});
const options = {
project_name: 'latstest',
auth: { token_secret: 'my_super_secret_secret' },
};
const horizonServer = horizon(httpServer, options);
app.use(express.static('./public'));
app.get('/',(req,res) => {
res.sendfile('public/index.html')
});
console.log('Server Initializing');
Main.js
import React from 'react';
import ReactDOM from 'react-dom';
const Horizon = require('@horizon/client');
const horizon = Horizon({ secure: false });
const chat = horizon("messages");
export default class App extends React.Component{
componentDidMount(){
let message = {
text: "What a beautiful horizon!",
datetime: new Date(),
author: "@dalanmiller"
};
chat.store(message)
}
render(){
return(
<div>
Hello from React js
</div>
)
}
}
ReactDOM.render(<App/>,document.getElementById('app'))
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="/horizon/horizon.js"></script>
<script>
var horizon = Horizon();
horizon.onReady(function () {
console.log('COnnet');
document.querySelector('h1').innerHTML = 'It is working'
});
horizon.connect();
</script>
</head>
<body>
<h1>didi</h1>
<div id="app"></div>
<script src="./bundle.js"></script>
</body>
</html>