Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: fix missing async in createServer callback #20

Merged
merged 3 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { once } from 'node:events';
import { fromNodeSocket } from 'pg-gateway/node';

// Create a TCP server and listen for connections
const server = createServer((socket) => {
const server = createServer(async (socket) => {
// Returns a `PostgresConnection` which manages the protocol lifecycle
const connection = await fromNodeSocket(socket);
});
Expand Down Expand Up @@ -458,10 +458,10 @@ With `pg-gateway`, we can serve PGlite over TCP by handling the startup/auth our

```typescript
import { PGlite } from '@electric-sql/pglite';
import net from 'node:net';
import { createServer } from 'node:net';
import { fromNodeSocket } from 'pg-gateway/node';

const server = net.createServer((socket) => {
const server = createServer(async (socket) => {
// Each connection gets a fresh PGlite database,
// since PGlite runs in single-user mode
// (alternatively you could queue connections)
Expand Down Expand Up @@ -508,7 +508,7 @@ You can test the connection using `psql`:
psql -h localhost -U postgres
```

You should be prompted for a password (`postgres`) and then brought into the `psql` REPL. At this point you are communicating directly with PGlite.
You should immediately be brought into the `psql` REPL. At this point you are communicating directly with PGlite.

### Reverse Proxy using SNI

Expand Down Expand Up @@ -548,7 +548,7 @@ async function getServerById(id: string) {
};
}

const server = createServer((socket) => {
const server = createServer(async (socket) => {
const connection = await fromNodeSocket(socket, {
tls,
// This hook occurs before startup messages are received from the client,
Expand Down Expand Up @@ -669,12 +669,6 @@ _/etc/hosts_

On Windows this file lives at `C:\Windows\System32\Drivers\etc\hosts`.

## Development

```shell
npm run dev
```

## License

MIT
10 changes: 5 additions & 5 deletions examples/pglite-auth/cert.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { PGlite } from '@electric-sql/pglite';
import fs from 'node:fs';
import net from 'node:net';
import { readFile } from 'node:fs/promises';
import { createServer } from 'node:net';
import { fromNodeSocket } from 'pg-gateway/node';

const db = new PGlite();

const server = net.createServer(async (socket) => {
const server = createServer(async (socket) => {
const connection = await fromNodeSocket(socket, {
serverVersion: '16.3 (PGlite 0.2.0)',
tls: {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem'),
key: await readFile('key.pem'),
cert: await readFile('cert.pem'),
},
auth: {
method: 'cert',
Expand Down
4 changes: 2 additions & 2 deletions examples/pglite-auth/md5.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { PGlite } from '@electric-sql/pglite';
import net from 'node:net';
import { createServer } from 'node:net';
import { createPreHashedPassword } from 'pg-gateway';
import { fromNodeSocket } from 'pg-gateway/node';

const db = new PGlite();

const server = net.createServer(async (socket) => {
const server = createServer(async (socket) => {
const connection = await fromNodeSocket(socket, {
serverVersion: '16.3 (PGlite 0.2.0)',
auth: {
Expand Down
4 changes: 2 additions & 2 deletions examples/pglite-auth/password.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { PGlite } from '@electric-sql/pglite';
import net from 'node:net';
import { createServer } from 'node:net';
import { fromNodeSocket } from 'pg-gateway/node';

const db = new PGlite();

const server = net.createServer(async (socket) => {
const server = createServer(async (socket) => {
const connection = await fromNodeSocket(socket, {
serverVersion: '16.3 (PGlite 0.2.0)',
auth: {
Expand Down
4 changes: 2 additions & 2 deletions examples/pglite-auth/scram-sha-256.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { PGlite } from '@electric-sql/pglite';
import net from 'node:net';
import { createServer } from 'node:net';
import { createScramSha256Data } from 'pg-gateway';
import { fromNodeSocket } from 'pg-gateway/node';

const db = new PGlite();

const server = net.createServer(async (socket) => {
const server = createServer(async (socket) => {
const connection = await fromNodeSocket(socket, {
serverVersion: '16.3 (PGlite 0.2.0)',
auth: {
Expand Down
4 changes: 2 additions & 2 deletions examples/pglite-auth/trust.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { PGlite } from '@electric-sql/pglite';
import net from 'node:net';
import { createServer } from 'node:net';
import { fromNodeSocket } from 'pg-gateway/node';

const db = new PGlite();

const server = net.createServer(async (socket) => {
const server = createServer(async (socket) => {
const connection = await fromNodeSocket(socket, {
serverVersion: '16.3 (PGlite 0.2.0)',
auth: {
Expand Down
4 changes: 2 additions & 2 deletions examples/pglite-multiple/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PGlite, type PGliteInterface } from '@electric-sql/pglite';
import { mkdir, readFile } from 'node:fs/promises';
import net from 'node:net';
import { createServer } from 'node:net';
import { type TlsOptionsCallback, createPreHashedPassword } from 'pg-gateway';
import { fromNodeSocket } from 'pg-gateway/node';

Expand All @@ -21,7 +21,7 @@ function getIdFromServerName(serverName: string) {
return id;
}

const server = net.createServer(async (socket) => {
const server = createServer(async (socket) => {
let db: PGliteInterface;

const connection = await fromNodeSocket(socket, {
Expand Down