Skip to content

Commit c803a37

Browse files
committed
improve Port and readme in example
1 parent dcd6717 commit c803a37

5 files changed

Lines changed: 25 additions & 7 deletions

File tree

examples/adonisjs/.env.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ NODE_ENV=development
33
PORT=3333
44
HOST=localhost
55
LOG_LEVEL=debug
6-
PUBLIC_URL=http://localhost:3333
6+
# The address remote servers reach this app at, e.g. a "fedify tunnel" URL.
7+
# Leave it unset for local development: the origin then follows whatever
8+
# port the server actually binds.
9+
#PUBLIC_URL=https://example.pinggy.link
710
# A throwaway key so that "cp .env.example .env" boots. Generate your own
811
# with "node ace generate:key" before deploying anything real.
912
APP_KEY=exampleAppKeyReplaceMeBeforeUse32

examples/adonisjs/README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ Running the example
4646

4747
The application listens on <http://localhost:3333> and the actor is `demo`.
4848

49-
> [!IMPORTANT]
49+
> [!NOTE]
5050
> `node ace serve` falls back to a free random port when 3333 is already
51-
> taken, and it prints the address it settled on.
51+
> taken, and it prints the address it settled on. Use that port in the
52+
> commands below; with `PUBLIC_URL` unset the actor URIs follow it
53+
> automatically.
5254

5355
3. Open _http://localhost:3333/_. Browsers asking for HTML at
5456
_http://localhost:3333/users/demo_ get the profile page:
@@ -64,6 +66,13 @@ Running the example
6466
http://localhost:3333/users/demo | jq
6567
~~~~
6668

69+
The [Fedify CLI] can look the actor up the same way, and `-a` signs the
70+
request the way a remote server would:
71+
72+
~~~~ sh
73+
pnpx @fedify/cli lookup http://localhost:3333/users/demo -a
74+
~~~~
75+
6776
4. Localhost is not reachable from other servers, so to actually exchange
6877
activities you need a public address. The [Fedify CLI] provides one:
6978

examples/adonisjs/config/fedify.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ export default defineConfig({
99
|
1010
| Fedify mints actor URIs, activity IDs and collection URLs from this
1111
| value, so it has to be the address remote servers can reach, not the
12-
| address Node happens to be listening on.
12+
| address Node happens to be listening on. Set PUBLIC_URL to the tunnel
13+
| or deployment address for that.
14+
|
15+
| Without PUBLIC_URL the origin follows the port the server actually
16+
| bound: "node ace serve" picks a free one when PORT is taken and passes
17+
| it to the app, so local lookups keep working after such a fallback.
1318
|
1419
*/
15-
origin: env.get("PUBLIC_URL"),
20+
origin: env.get("PUBLIC_URL") ??
21+
`http://${env.get("HOST")}:${env.get("PORT")}`,
1622
});

examples/adonisjs/start/env.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ export default await Env.create(new URL("../", import.meta.url), {
2323
| Variables for configuring Fedify
2424
|----------------------------------------------------------
2525
*/
26-
PUBLIC_URL: Env.schema.string({ format: "url", tld: false }),
26+
PUBLIC_URL: Env.schema.string.optional({ format: "url", tld: false }),
2727
});

packages/adonisjs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Requirements
3535
------------
3636

3737
- AdonisJS 7.0 or later
38-
- Fedify 2.3.4 or later
38+
- Fedify 2.4.0 or later
3939
- Node.js 24 or later — and Node.js only; see below
4040

4141
The package ships both ESM and CommonJS builds. The CommonJS one works because

0 commit comments

Comments
 (0)