-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
45 lines (37 loc) · 1.05 KB
/
server.js
File metadata and controls
45 lines (37 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const express = require("express");
const dotenv = require("dotenv");
const path = require("path");
const app = express();
dotenv.config();
const port = +process.env.PORT || 5555;
const pubkey = process.env.PUBKEY;
const username = process.env.NAME || "_";
const nostr = JSON.parse(`
{
"names": {
"${username}": "${pubkey}"
}
}
`);
// Need CORS for nostr web clients to be able to make requests to this server
app.use((_, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept"
);
next();
});
app.set("views", path.join(__dirname, "public"));
app.set("view engine", "ejs");
app.use(express.static(path.join(__dirname, "public")));
// Serve the json file required by nostr clients with NIP-05
app.get("/.well-known/nostr.json", (_, res) => {
res.json(nostr);
});
app.get("/", (_, res) => {
res.render(path.join("index"), { pubkey, username });
});
app.listen(port, () => {
console.log("App is running on ", port);
});