-
Getting Started
-
The Basics
-
Architecture Concepts
*
- TODO
To learn about Syncano Sockets visit documentation.
import Syncano from 'syncano-server'
export default async ctx => {
// Initialize Syncano Server Library
const {data, response} = new Syncano(ctx)
// Check if user is authenticated
if (!ctx.meta.user) {
response.json({message: 'Unauthorized'}, 401)
process.exit(0)
}
// Get user id from Socket Context
const {id: author} = ctx.meta.user
const {title} = ctx.args
// Create post
const post = await data.posts.create({title, author})
// Respond with created post
response.json(post)
}
To install Syncano Server Library, use npm or yarn in your socket.
npm i syncano-server --save