Part 1: Server Setup

Here you will find a step by step tutorial on installing Leia WebGL SDK and dealing with server configuration. This tutorial assumes you do not yet have npm in your project and you do have your static html and js and other files in public/ subdirectory

Setup

To get started, you need to initialize your npm:

npm init 

Now we need to install a server. In this example, we will use express:

npm install express 

Example server app script. Our example is named node server_app_script.js and was saved in project root directory.

npm install leiawebglsdk

Running the Server

You can run the server either through a node command

node server_app_script.js 

Or you can add the command to your package.json:

"scripts": { 
    "start": "node server_app_script.js"
},

And then run server like this:

npm start

Integrating Leia WebGL SDK

Full server script:

var express = require('express');
var server = express();
server.use('/leiawebglsdk/', express.static(process.cwd() + '/node_modules/leiawebglsdk/src/', {extensions:['js']})); 
server.use(express.static(process.cwd() + '/public')); //assumes static html and js files are in public/ subdirectory
server.listen(3000);
console.log("open 127.0.0.1:3000 in your browser");

Note the following line from the script above configures our server to reference the Leia WebGL SDK. Without this reference, we will get error message 'RenderController is not found':

server.use('/leiawebglsdk/', express.static(process.cwd() + '/node_modules/leiawebglsdk/src/', {extensions:['js']})); 

Last updated

Copyright © 2023 Leia Inc. All Rights Reserved