33 * @module capability-discovery
44 */
55const express = require ( 'express' )
6- const restrictToTopDomain = require ( './handlers/restrict-to-top-domain' )
7-
8- const serviceConfigDefaults = {
9- 'api' : {
10- 'accounts' : {
11- // 'changePassword': '/api/account/changePassword',
12- // 'delete': '/api/accounts/delete',
13-
14- // Create new user (see IdentityProvider.post() in identity-provider.js)
15- 'new' : '/api/accounts/new' ,
16- 'recover' : '/api/accounts/recover' ,
17- 'signin' : '/login' ,
18- 'signout' : '/logout' ,
19- 'validateToken' : '/api/accounts/validateToken'
20- }
21- }
22- }
6+ const { URL } = require ( 'url' )
237
248module . exports = capabilityDiscovery
259
@@ -32,7 +16,7 @@ function capabilityDiscovery () {
3216 const router = express . Router ( '/' )
3317
3418 // Advertise the server capability discover endpoint
35- router . get ( '/.well-known/solid' , restrictToTopDomain , serviceCapabilityDocument ( serviceConfigDefaults ) )
19+ router . get ( '/.well-known/solid' , serviceCapabilityDocument ( ) )
3620 return router
3721}
3822
@@ -44,12 +28,27 @@ function capabilityDiscovery () {
4428 * @param res
4529 * @param next
4630 */
47- function serviceCapabilityDocument ( serviceConfig ) {
31+ function serviceCapabilityDocument ( ) {
4832 return ( req , res ) => {
49- // Add the server root url
50- serviceConfig . root = req . app . locals . ldp . resourceMapper . resolveUrl ( req . hostname , req . path )
51- // Add the 'apps' urls section
52- serviceConfig . apps = req . app . locals . appUrls
53- res . json ( serviceConfig )
33+ const ldp = req . app . locals . ldp
34+ res . json ( {
35+ // Add the server root url
36+ root : req . app . locals . ldp . resourceMapper . resolveUrl ( req . hostname , req . path ) ,
37+ // Add the 'apps' urls section
38+ apps : req . app . locals . appUrls ,
39+ api : {
40+ accounts : {
41+ // 'changePassword': '/api/account/changePassword',
42+ // 'delete': '/api/accounts/delete',
43+
44+ // Create new user (see IdentityProvider.post() in identity-provider.js)
45+ new : new URL ( '/api/accounts/new' , ldp . serverUri ) ,
46+ recover : new URL ( '/api/accounts/recover' , ldp . serverUri ) ,
47+ signin : req . app . locals . ldp . resourceMapper . resolveUrl ( req . hostname , '/login' ) ,
48+ signout : req . app . locals . ldp . resourceMapper . resolveUrl ( req . hostname , '/logout' ) ,
49+ validateToken : new URL ( '/api/accounts/validateToken' , ldp . serverUri )
50+ }
51+ }
52+ } )
5453 }
5554}
0 commit comments