{"_id":"561af4a878436c19009e87d8","category":{"_id":"561ae15563ef571900ca68d7","version":"561ae15463ef571900ca68d6","pages":["561ae15563ef571900ca68d9","561af2911a10ea0d002387f7","561af4a878436c19009e87d8","561c3b3400e13c0d00936286","56327cdb38f8aa0d00d30f6e","566b532068eba90d009cac6c","5672df821e18b60d00b04a32"],"project":"561ae15363ef571900ca68d3","__v":7,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-10-11T22:23:17.043Z","from_sync":false,"order":0,"slug":"documentation","title":"Documentation"},"githubsync":"","__v":10,"version":{"_id":"561ae15463ef571900ca68d6","project":"561ae15363ef571900ca68d3","__v":3,"createdAt":"2015-10-11T22:23:16.492Z","releaseDate":"2015-10-11T22:23:16.492Z","categories":["561ae15563ef571900ca68d7","56255c864dcb400d00ff4427","56326faf45f2cb0d006be3f1"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"project":"561ae15363ef571900ca68d3","user":"561ae13963ef571900ca68d2","updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-10-11T23:45:44.909Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":5,"body":"Some developers wish to configure their own backend to host and serve builds to mobile clients. This is an advanced feature; most developers will choose to use AppHub hosting and the AppHub developer dashboard.\n\nHere we provide a basic outline for the endpoints that must be implemented by a build-hosting server, as well as a minimal `Node.js` implementation.\n\n---\n\n## Server Endpoints\n\nFrom the AppHub client, configure the `rootURL` to point to your server at the beginning of the `applicationDidFinishLaunching:withOptions` in `AppDelegate.m`:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[AppHub setRootURL::::at:::\\\"http://localhost:3000\\\"];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nThe server must respond to a `GET` request to `/projects/:projectId/build`.\n\nPossible query parameters are:\n- `app_version`: The device's native app version.\n- `debug`: `1` if the device is in debug mode, `0` otherwise.\n- `device_uid`: The device's unique identifier.\n- `sdk_version`: The device's version of the AppHub client SDK.\n\nThe response must be a JSON one of the following two forms:\n\n### No Build Available\n\nIf there is no new build available (the client should use the bundled JavaScript), respond with a `NO-BUILD` response:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n\\tstatus: 'success',\\n  data: {\\n    type: 'NO-BUILD',\\n  }\\n}\",\n      \"language\": \"json\",\n      \"name\": \"No Build Available Response\"\n    }\n  ]\n}\n[/block]\n### Build Available\n\nIf there a new build available, the server responds with a `GET-BUILD` response. All fields are required (though some might not be used by the client):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n\\tstatus: 'success',\\n  data: {\\n  \\ttype: 'GET-BUILD',\\n    \\n    // The project id as configured on the client. Must match exactly \\n    // the value passed to [AppHub setApplicationID:@\\\"\\\"].\\n    project_uid: '',\\n\\n    // A consistent id for the build, such as the key or hash.\\n    // The AppHub client uses this id to determine whether the\\n    // most current build has changed.\\n    uid: '',\\n\\n    // Name for the build.\\n    name: '',\\n\\n    // Description for the build.\\n    description: '',\\n\\n    // URL of the zipped build. Does not necessarily have to be an s3 url.\\n    s3_url: '',\\n\\n    // Epoch time in milliseconds since 1970 when the build was\\n    // created. This is only used for metadata, not to determine\\n    // whether the build should be used.\\n    created: 0,\\n\\n    // Native app versions for which the build is compatible.\\n    // The official AppHub client only uses the values of the object, not the keys.\\n    app_versions: {\\n      '1.0': '1.0',\\n    }\\n\\t}\\n}\",\n      \"language\": \"json\",\n      \"name\": \"Build Available Response\"\n    }\n  ]\n}\n[/block]\n---\n\n## Minimal Server Implementation\n\nSee [https://github.com/AppHubPlatform/apphub-simple-server](https://github.com/AppHubPlatform/apphub-simple-server) for a reference implementation in Node.\n\n---\n\n## Creating New Builds\n\nUse the [AppHub CLI](doc:apphub-cli) to create new builds of your app. You can use s3, or any other static hosting server to host the builds. We recommend using a CDN to improve performance.","excerpt":"Host AppHub on your own servers.","slug":"self-hosting","type":"basic","title":"Hosting an AppHub Server"}

Hosting an AppHub Server

Host AppHub on your own servers.

Some developers wish to configure their own backend to host and serve builds to mobile clients. This is an advanced feature; most developers will choose to use AppHub hosting and the AppHub developer dashboard. Here we provide a basic outline for the endpoints that must be implemented by a build-hosting server, as well as a minimal `Node.js` implementation. --- ## Server Endpoints From the AppHub client, configure the `rootURL` to point to your server at the beginning of the `applicationDidFinishLaunching:withOptions` in `AppDelegate.m`: [block:code] { "codes": [ { "code": "[AppHub setRootURL:@\"http://localhost:3000\"];", "language": "objectivec" } ] } [/block] The server must respond to a `GET` request to `/projects/:projectId/build`. Possible query parameters are: - `app_version`: The device's native app version. - `debug`: `1` if the device is in debug mode, `0` otherwise. - `device_uid`: The device's unique identifier. - `sdk_version`: The device's version of the AppHub client SDK. The response must be a JSON one of the following two forms: ### No Build Available If there is no new build available (the client should use the bundled JavaScript), respond with a `NO-BUILD` response: [block:code] { "codes": [ { "code": "{\n\tstatus: 'success',\n data: {\n type: 'NO-BUILD',\n }\n}", "language": "json", "name": "No Build Available Response" } ] } [/block] ### Build Available If there a new build available, the server responds with a `GET-BUILD` response. All fields are required (though some might not be used by the client): [block:code] { "codes": [ { "code": "{\n\tstatus: 'success',\n data: {\n \ttype: 'GET-BUILD',\n \n // The project id as configured on the client. Must match exactly \n // the value passed to [AppHub setApplicationID:@\"\"].\n project_uid: '',\n\n // A consistent id for the build, such as the key or hash.\n // The AppHub client uses this id to determine whether the\n // most current build has changed.\n uid: '',\n\n // Name for the build.\n name: '',\n\n // Description for the build.\n description: '',\n\n // URL of the zipped build. Does not necessarily have to be an s3 url.\n s3_url: '',\n\n // Epoch time in milliseconds since 1970 when the build was\n // created. This is only used for metadata, not to determine\n // whether the build should be used.\n created: 0,\n\n // Native app versions for which the build is compatible.\n // The official AppHub client only uses the values of the object, not the keys.\n app_versions: {\n '1.0': '1.0',\n }\n\t}\n}", "language": "json", "name": "Build Available Response" } ] } [/block] --- ## Minimal Server Implementation See [https://github.com/AppHubPlatform/apphub-simple-server](https://github.com/AppHubPlatform/apphub-simple-server) for a reference implementation in Node. --- ## Creating New Builds Use the [AppHub CLI](doc:apphub-cli) to create new builds of your app. You can use s3, or any other static hosting server to host the builds. We recommend using a CDN to improve performance.