I'm trying to build a simple nodejs server to test unity3d on a server. I tested my empty scene alone and it work pretty well with WebGL. after this, i've put the file of WebGL in my NodeJS server and i get this error: Invoking error handler due to UnityLoader.js:1 Uncaught SyntaxError: Unexpected token < What is causing this error? Here is my nodejs server code: Code (JavaScript): import * as http from 'http'; import * as express from 'express'; import { json, urlencoded } from 'body-parser'; import * as compression from 'compression'; import * as path from 'path'; const port: number = process.env.port || 1337; const app: express.Application = express(); const clientFolder: string = path.join(__dirname, '/client'); app.use(json()); app.use(compression()); app.use(urlencoded({ extended: true })); app.use(express.static(clientFolder)); app.use(defaultRoute); http .createServer(app) .listen(port); function defaultRoute(req: express.Request, response: express.Response) : void { response.sendfile(clientFolder + '/index.html'); } EDIT: My probleme come from those urls dataUrl: "Release/build.data", codeUrl: "Release/build.js", asmUrl: "Release/build.asm.js", memUrl: "Release/build.mem", my nodejs return index.html code instead of the files required by unity3d
does it work if you host a development build? if so, you just need to make sure you set the content type headers when hosting a non-development build (which is compressed). See here for more details.
You should use express static files, you're not serving your client correctly. For example, this is a server of my own: Code (csharp): var express = require('express'); var compression = require('compression'); var app = express(); app.use(compression()); app.use(express.static(__dirname + '/client/')); app.listen(80, function(){ console.log("webserver listening!"); }); Doing it this way, you will send a whole folder (the client folder). I think your problem is that your express server isn't sending out all the client files. Edit: nevermind you're using the static files, so idk. My way works flawless!
The best thing to do is to change the link from e.g. Release/build.data to https://yourwebsitelink.com/files/Release/build.data
Serving the whole webgl folder did not work for me The error I got was this... When I enabled Decompress Fallback, however, it did work. In fact, I got it running on an Elastic Beanstalk server. This was my very simple final code: Code (JavaScript): var express = require('express'); var compression = require('compression'); var app = express(); app.use(compression()); app.use(express.static('client')); app.listen(8080, function(){ console.log("webserver listening at port: " + 8080); }); Hope it helps.