Whether you are building an application or a website, the first thing you’ll need is a SAFE Browser that is built for mock-routing.
What is mock-routing and why?
When the SAFE Browser, or another application, is built with mock-routing enabled, it’s not connecting to a live network, it’s interfacing with a local database that is created on your system to simulate network operations.
This saves a great deal of time and provides a safe space for your application or website to initially test operations.
Building the SAFE Browser for mock-routing
If you’d like to build your own browser, you can go to the SAFE Browser repository and follow the instructions in the README.
The first thing you need to do is make sure you have an environment variable of NODE_ENV
set to dev
.
-
On a Linux-based OS or on macOS, you can create a shell variable that will last as long as the shell session, simply with
export NODE_ENV=dev
-
On Windows, using Powershell, you may set a shell variable that also only lasts as long as the shell session with,
$env:NODE_ENV = 'dev'
Then follow the steps in the repo’s README, summarised as follows: yarn && yarn run build
Before running yarn run package
, run yarn start
first to verify that the browser was built successfully and to check for errors in your terminal. Then you can spend the time to package a browser binary with yarn run package
.
At this point, you have a running SAFE Browser that is solely interfacing with mock-routing on your system. This is enough if you are only developing a website for the SAFE Network.
Developing a SAFE website
Clone this repository, cd
into safe_web_api_playground
, and follow the instructions in the README to get server started.
Open a new tab in the SAFE Browser and navigate to localhost://p:3003
, where you’ll be able to view the site and work with the SAFE Web API. Try making changes in the code and see how gulp
is watching for file changes so that you don’t have to restart the server. Just refresh your browser tab.
Using this repo as an example of how to quickly develop your own site:
-
Run
npm init
in your own project folder, follow command-line instructions, and then observe your newly createdpackage.json
file -
Run
npm install --save express body-parser
-
Copy
gulpfile.js
into your project folder, if you’d like to automate tasks like restarting the server and concatenating JS modules. Otherwise you don’t need it but it does speed up development. If you do want to use it, be sure tonpm install gulp -g
-
Copy the
index.js
file into your project folder. This program serves yourindex.html
and broadcasts it on port 3003.
If you are working with gulpfile.js
, simply run gulp
.
If you are not working with gulp
, simply run node index
and your server will start.
Building applications for mock-routing
If building one of the SAFE example apps, like Web Hosting Manager or SAFE Mail Tutorial, simply set NODE_ENV=dev
, using the same suggestions as above for building a SAFE Browser.
If building your own application, there are a number of options depending on what you need. Take a look at this very basic Electron application, GitHub - hunterlester/safe-app-base, which uses the SAFE App Node.js library as a dependency to connect to the network.
Your application will send requests to the authenticator client, which is integrated with the SAFE Browser, and listen for responses.
Mock-routing errors
At some point you may start running into errors like Access denied...
or Entry does not exist...
, while using the Web API. If this is the case, you can delete your local MockVault
file and restart your SAFE Browser.
The MockVault
file is stored in a different path depending on your platform. Use this document to find where it is on your system.
Moving to a test network
After testing and getting familiarised with network operations on mock-routing, the next step is to move your application to a test network, which is live but is not the public SAFE Network. This phase will help pick up errors that may not have been able to be simulated in mock-routing.
The MaidSafe developer team will have binaries available for download for the SAFE Browser and for the SAFE App Node.js library that specifically connect to a developer test network. Hosting your application on a test network is a good way to get other users to test your application.
The latest test network is Alpha 2. See this topic for more info.
Another option is to run your own local test network. See this topic for more info.
Moving to the public SAFE Network
Once you are done with mock-routing and the test network, your application, if using the SAFE App Node.js library to interface with the network for example, will need a library that is set to connect with the primary live network.
There is no live network yet. See MaidSafe’s roadmap for more information on upcoming releases.