Create server/package.json
with:
{
"name": "server",
"private": true,
"type": "module",
"scripts": {
"start": "node --experimental-strip-types --watch index.ts"
}
}
Install Logux Server:
npm i @logux/server
pnpm add @logux/server
yarn add @logux/server
Create index.ts
with:
import { Server } from '@logux/server'
import { SUBPROTOCOL } from '../api/index.js'
const server = new Server(
Server.loadOptions(process, {
subprotocol: SUBPROTOCOL,
supports: '1.x',
fileUrl: import.meta.url
})
)
server.auth(async ({ userId, token }) => {
// Allow only local users until we will have a proper authentication
return process.env.NODE_ENV === 'development'
})
server.listen()
The simple Logux server is ready. You can start it with:
npm start
pnpm start
yarn start
To stop the server press Command+. on Mac OS X and Ctrl+C on Linux and Windows.
Look at Node.js API to learn server API.