Can you test a module from a local EspruinoDocs server

Posted on
  • So i have a module that i've made.
    I've tested it locally by saving it to a file on the device i'm working on and it works fine. I've also pulled the EspruinoDocs and compiled it to make sure that the documentation looks fine.

    Now can i do one final test where i load it from my local EpsruinoDocs instance.

    I run npm run start after doing a build.sh and i can see my webpage of my new module. But i can't seem to see it in the browser or from the device.

    I set the module loading location to  http://localhost:3040/devices

    Any thoughts

  • If the Web IDE's library search path includes the folder then I'd have thought it should be able to find it just fine?

    It might be worth checking the debug console on your web browser - maybe the web server created by npm run start doesn't have the CORS headers set so the IDE can't access it

  • So i think the problem i'm having is this.
    On the web folder explorer i can see this gives me a list of js files

    But when i do http://localhost:3040/modules - i get

    • Cannot GET /modules


    As for the debug console. I don't see any errors.
    It loads

    • modules name html
    • offline.css
    • and a refimage
  • So this is my current understanding

    app.js is the way the websites served. It serves the content inside EspruinoDocs/html. This file includes all the files that got generated from the markdown modules.

    Now the the javascript modules are in. So they they never get served up from the server.

    [#buildmodules](https://forum.espruino.c­om/search/?q=%23buildmodules).sh
    DIR=`pwd`
    WEBSITE="$HOME/workspace/espruinowebsite­"
    MODULEDIR=$WEBSITE/www/modules
    

    So i changed the location

    DIR=`pwd`
    WEBSITE="$DIR/html"
    MODULEDIR=$WEBSITE/modules
    

    and now the ide will grab the files it just doesn't use it?

    So i can see from the server it serves the files.
    //terminal from app start
    returning: /modules/BH1792.min.js
    returning: /modules/BH1792.js

    but from the ide perspective i still get.
    "Module BH1792 not found"

  • Sorry my bad! When you suggested look at the web ide. I thought you were talking about on the actual web page. So module.html.. I saved the espruino app to my desktop, so i forget it's actually a web page.

    So yes the problem is that in chrome it doesn't accept none secure local host files. The specific problem.

    Access to fetch at 'http://localhost:3040/modules/BH1792.min­.js' from
    origin 'https://www.espruino.com' has been blocked by CORS policy: No
    'Access-Control-Allow-Origin' header is present on the requested
    resource. If an opaque response serves your needs, set the request's
    mode to 'no-cors' to fetch the resource with CORS disabled.

  • @Gordon

    So it was a fairly easy fix to stop the CORS problem.

    var express = require('express');
    const cors = require('cors');
    var app = express();
    app.use(cors());
    

    If i understand this properly this app.js is just testing. So if that's the case. I can push this simple fix and redirect anything that's trying to load a file from localhost:3040/modules to ~/workspace/espruinowebsite/www/modules

  • This looks great, thanks for the PR!

    I guess the redirect to ~/workspace/espruinowebsite/www/modules isn't ideal - but as you say it's just for testing...

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Can you test a module from a local EspruinoDocs server

Posted by Avatar for user156811 @user156811

Actions