GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — node-solid-server/lib/payment-pointer-discovery.mjs at main · nodeSolidServer/node-solid-server

Expand file tree

/

payment-pointer-discovery.mjs

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
80 lines (76 loc) · 2.51 KB
/

payment-pointer-discovery.mjs

Copy path

File metadata and controls

80 lines (76 loc) · 2.51 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* @module payment-pointer-discovery
*/
import express from 'express'
import { promisify } from 'util'
import fs from 'fs'
import rdf from 'rdflib'
const PROFILE_PATH = '/profile/card'
/**
* Returns a set of routes to deal with server payment pointer discovery
* @method paymentPointerDiscovery
* @return {Router} Express router
*/
export default function paymentPointerDiscovery () {
const router = express.Router('/')
// Advertise the server payment pointer discover endpoint
router.get('/.well-known/pay', paymentPointerDocument())
return router
}
/**
* Serves the service payment pointer document (containing server root URL, including
* any base path the user specified in config, server API endpoints, etc).
* @method paymentPointerDocument
* @param req
* @param res
* @param next
*/
function paymentPointerDocument () {
return async (req, res) => {
try {
const ldp = req.app.locals.ldp
const url = ldp.resourceMapper.resolveUrl(req.hostname, PROFILE_PATH)
const contentType = 'text/turtle'
const createIfNotExists = false
const { path } = await ldp.resourceMapper.mapUrlToFile({ url, contentType, createIfNotExists })
let body
try {
// Read the file from disk
body = await promisify(fs.readFile)(path, { encoding: 'utf8' })
} catch (e) {
if (e.message.startsWith('ENOENT: no such file or directory,')) {
res.json({
error: `Please create ${PROFILE_PATH} on your pod`
})
}
}
const webid = rdf.Namespace(`${url}#`)('me')
const pp = rdf.Namespace('http://paymentpointers.org/ns#')('PaymentPointer')
let paymentPointer
try {
const graph = rdf.graph()
// Parse the file as Turtle
rdf.parse(body, graph, url, contentType)
paymentPointer = graph.any(webid, pp)
} catch (e) {
console.error(e)
res.json({
error: `Please make sure ${PROFILE_PATH} contains valid Turtle`
})
}
if (paymentPointer === null) {
res.json({ fail: 'Add triple', subject: `<${webid.value}>`, predicate: `<${pp.value}>`, object: '$alice.example' })
}
if (paymentPointer.value.startsWith('$')) {
let suffix = ''
if (paymentPointer.value.indexOf('/') === -1) {
suffix = '/.well-known/pay'
}
paymentPointer.value = `https://${paymentPointer.value.substring(1)}${suffix}`
}
res.redirect(paymentPointer.value)
} catch (e) {
res.json({ fail: e.message })
}
}
}
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.