Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How to host unity webGL on node.js?

Discussion in 'WebGL' started by vemmu, Jul 26, 2022.

  1. vemmu

    vemmu

    Joined:
    May 15, 2022
    Posts:
    8
    I was following this thread https://forum.unity.com/threads/nodejs-as-server-for-hosting-webgl.449904/

    I am trying to get my unity webGL project to show up as static using node.js but terminal is throwing me this error "TypeError: Object prototype may only be an Object or null: /Testit"

    This is my code at the moment:
    Code (JavaScript):
    1. const express = require('express');
    2. var compression  = require('compression');
    3. const app = express();
    4.  
    5. app.use(compression());
    6. app.use(express.static(__dirname,'/Testit'));
    7.  
    8.  
    9. app.listen(8000, () => {
    10. console.log('Server has started!')
    11. });
    Thanks in advance!
     
  2. aromana

    aromana

    Joined:
    Nov 11, 2018
    Posts:
    137
    Line 6 isn't correct. It looks like you meant to call path.join() to create the path name, and pass that to express.static().

    Presumably, you want:
    Code (JavaScript):
    1. const path = require('path')
    2. app.use(express.static(path.join(__dirname, 'Testit')));
    You could probably also do something simpler, but hackier, and create the path with simple string concatenation, like this:

    Code (JavaScript):
    1. app.use(express.static(__dirname + '/Testit'));
     
    vemmu likes this.
  3. vemmu

    vemmu

    Joined:
    May 15, 2022
    Posts:
    8
    Thank you! This fixed it for me
     
    xiangshushu likes this.