Skip to content

Commit

Permalink
website
Browse files Browse the repository at this point in the history
  • Loading branch information
Cesar Casas committed Jun 28, 2024
1 parent b4f76ad commit 4234281
Show file tree
Hide file tree
Showing 55 changed files with 2,760 additions and 12 deletions.
98 changes: 98 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
- [Documentation](#documentation)
- [Installation](#installation)
- [Example Implementation for listen Events](#example-implementation-for-listen-events)
- [Creating controllers](#creating-controllers)
- [Using controllers](#using-controllers)
- [Creating a Monorepo with Microservices](#creating-a-monorepo-with-microservices)

**Author**: César Casas
Expand Down Expand Up @@ -148,6 +150,102 @@ export function listenEventsDomain(eventsDomain: EventsDomain) {

```

### Creating controllers
```typescript
import { Dependencies, type MongoClient, type EventsDomain, Controller } from 's42-core'
import { z } from 'zod'

const TypeUser = z.object({
firstName: z.string(),
lastName: z.string(),
email: z.string().email(),
})

export const userController = new Controller()
.setPath('/users/create')
.post()
.use(async (req, res, next) => {
console.info('This is a mws: ', req.query)
next()
})
.use(async (req, res) => {
const db = Dependencies.get<MongoClient>('db') as MongoClient
const eventsDomain = Dependencies.get<EventsDomain>('eventsDomain') as EventsDomain

try {
const data = req.body
TypeUser.parse(data)
await db.getCollection('users').insertOne({
...data,
remoteIp: req.realIp,
added: new Date(),
headers: req.headers,
})

eventsDomain.emitEvent('users.created', { ...data })
res.json({ ok: true })
} catch (error) {
res.jsonError({ ok: false, msg: error })
}
})

```

### Using controllers
```typescript
import { createServer } from 'node:http'

import {
Shutdown,
Cluster,
Dependencies,
MongoClient,
RedisClient,
EventsDomain,
RouteControllers,
} from 's42-core'

import { userController, healthController } from './controllers'

const port = process.env.PORT ?? 3000

Cluster(
1,
async (pid, uuid) => {
console.info('initializing: ', pid, uuid)
const mongoClient = MongoClient.getInstance({
connectionString: String(process.env?.MONGO_URI),
database: String(process.env?.MONGO_DB),
})

await mongoClient.connect()
const redisClient = RedisClient.getInstance('localhost')

const eventsDomain = EventsDomain.getInstance(redisClient, uuid)

Dependencies.add<MongoClient>('db', mongoClient)
Dependencies.add<RedisClient>('redis', redisClient)
Dependencies.add<EventsDomain>('eventsDomain', eventsDomain)

const routerControllers = RouteControllers.getInstance([
userController,
healthController,
])
const server = createServer(routerControllers.getCallback())

server.listen(port, () => {
console.info(`ready on *:${port}`)
})
Shutdown([mongoClient.close, redisClient.close, eventsDomain.close])
},
() => {
console.info('Error trying start servers')
},
)

```


### Creating a Monorepo with Microservices

![s42-core monorepo](./DOCUMENTATION/ecosystem-using-s42-core.png)
Expand Down
36 changes: 36 additions & 0 deletions docs/404.html

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added docs/_astro/android-chrome-512x512.CXG4s06D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions docs/_astro/ec.3zb7u.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/_astro/ec.d6kn2.css

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions docs/_astro/hoisted.BGYf8I8B.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/_astro/index.BBOKLJpq.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/_astro/page.LS5KDvwX.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added docs/_astro/s42-core.Dgcad_jT_1xRQ03.webp
Binary file not shown.
2 changes: 2 additions & 0 deletions docs/_astro/ui-core.Bl6eIf81.js

Large diffs are not rendered by default.

Binary file added docs/android-chrome-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/android-chrome-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/favicon.ico
Binary file not shown.
Loading

0 comments on commit 4234281

Please sign in to comment.