Hi, i have created the express server and inside t...
# talk-keto
m
Hi, i have created the express server and inside the / router i have placed the code for node grpc taken from this https://www.ory.sh/docs/keto/guides/simple-access-check-guide for creating tuples and i have installed the grpc client modules https://www.npmjs.com/package/@ory/keto-grpc-client . below is what my server code looks like it is very basic for now
import grpc from '@ory/keto-grpc-client/node_modules/@grpc/grpc-js/build/src/index.js'
import { acl, write, writeService } from '@ory/keto-grpc-client'
const express = require("express")
var cors = require('cors')
const app = express()
app.use(cors())
app.get("/",(req,res)=>{
console.log("welcome")
// res.send("working")
const writeClient = new writeService.WriteServiceClient(
'127.0.0.1:4467',
grpc.credentials.createInsecure()
)
const relationTuple = new acl.RelationTuple()
relationTuple.setNamespace('messages')
relationTuple.setObject('02y_15_4w350m3')
relationTuple.setRelation('decypher')
const sub = new acl.Subject()
sub.setId('john')
relationTuple.setSubject(sub)
const tupleDelta = new write.RelationTupleDelta()
tupleDelta.setAction(write.RelationTupleDelta.Action.INSERT)
tupleDelta.setRelationTuple(relationTuple)
const writeRequest = new write.TransactRelationTuplesRequest()
writeRequest.addRelationTupleDeltas(tupleDelta)
writeClient.transactRelationTuples(writeRequest, (error) => {
if (error) {
console.log('Encountered error', error)
} else {
console.log('Successfully created tuple')
res.send("successfully created tuples")
}
})
})
app.listen(5000)
but when i run the server i get the following error @steep-lamp-91158 @proud-plumber-24205 @damp-sunset-69236 @magnificent-energy-493
this is my folder structure
m
getting this error show in fig below when trying to hit the endpoint as mentioned above, by the way i have replaced
_import_ grpc _from_ '@ory/keto-grpc-client/node_modules/@grpc/grpc-js/build/src/index.js'
with
_import_ grpc _from_ '@ory/keto-grpc-client'
otherwise i was getting the error
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/aqib/OPENAIMP/nodereact/nodeExpressServer/node_modules/@ory/keto-grpc-client/node_modules/@grpc/grpc-js/build/src/index.js' imported from /home/aqib/OPENAIMP/nodereact/nodeExpressServer/server.js
s
it seems like somewhere in your code you do
x.createInsecure
but
x
is undefined
m
i did not change the code i just copied it from https://www.ory.sh/docs/keto/guides/simple-access-check-guide and running it
s
m
it was still giving me error so i converted curl to http for rest and used axios to send request and it worked.