skip to Main Content

I have a working forge application ( bim360 hub sidebar with forge viewer and some charts).

It is currently running from Visual Studio Code IDE only. I want to build the app into an .exe file in order to be able to send it to a user, upload it to a server with IIS, etc..

General details:

I tried to use ‘nexe’ module and build executable file. With this method, I need to specify index.js file ("an entry point") and define a ‘nexe.config.js’ file. I used the entry point start.js.
Eventually, I managed to create an exe file – and when I run it from the command line, I get an error

Missing FORGE_CLIENT_ID or FORGE_CLIENT_SECRET env. variables.

although I have them in the config.js

Main questions:

  • Is there another way to build a close exe file from visual studio code – for a forge web application?
  • Am i doing something wrong with the processes I mention above?
  • Is it even possible to deploy a web application to IIS using an exe file?? all of the documentation points toward Azur, AWS and heroku..

Relevant files:

1) start.js:

const path = require('path');//bringing in built in node js modeules ( to resulve file system path )
const express = require('express');//module to create the express server 
const cookieSession = require('cookie-session'); 
//any piece of code would have an opportunity to handle the request 
const PORT = process.env.PORT || 3000;
const config = require('./config.js');
if (config.credentials.client_id == null || config.credentials.client_secret == null) {
    console.error('Missing FORGE_CLIENT_ID or FORGE_CLIENT_SECRET env. variables.');
    return;
}

let app = express();
//static middlewere to check for the front end files (html,js,css)
app.use(express.static(path.join(__dirname, 'public')));//method inside express module: a middlewere for serving static files  this line will check in 'public' folder if the request 
//that is sent (specific file) is in there. if so - it will ignore the rest of the stack(the rest of the code)
app.use(cookieSession({
    // create 2 cookies that stores the name and encripted key 
    name: 'forge_session',
    keys: ['forge_secure_key'],//takes cater of decipher the encription for the forge key for us 
    maxAge: 14 * 24 * 60 * 60 * 1000 // 14 days, same as refresh token
}));
app.use(express.json({ limit: '50mb' }));//middlewere that looks at the title of the request - and if its .json it will look at the body of the request and parese it to javascript object
app.use('/api/forge', require('./routes/oauth.js'));//adding our custom express routers that will handle the different endpoints.
app.use('/api/forge', require('./routes/datamanagement.js'));
app.use('/api/forge', require('./routes/user.js'));
app.use((err, req, res, next) => {
    console.error(err);
    res.status(err.statusCode).json(err);
});
app.listen(PORT, () => { console.log(`Server listening on port ${PORT}`); });

2) config.js:

// Autodesk Forge configuration
module.exports = {
    // Set environment variables or hard-code here
    credentials: {
        client_id: process.env.FORGE_CLIENT_ID,
        client_secret: process.env.FORGE_CLIENT_SECRET,
        callback_url: process.env.FORGE_CALLBACK_URL
    },
    scopes: {
        // Required scopes for the server-side application-->privliges for our internal opperation in the server side ("back end")
        internal: ['bucket:create', 'bucket:read', 'data:read', 'data:create', 'data:write'],
        // Required scope for the client-side viewer-->priveliges for the client ("front end") 
        public: ['viewables:read']
    }
};

2

Answers


  1. Chosen as BEST ANSWER

    after trying a lot of solutions, i got to the conclusion that the reason that nothing happened was that the oathantication files ( with the clint_id and clint_password) was not embedded in the .exe file. the way to include those files with the nexe module is to use the flag -r "Foldername/subfoldername/filename.js".

    first, crate a nexe.config.js file that would contain the entry point file name to the app. ( in my case, the file name is " start.js") second, write the following commands in the command line:

    cd C:ProjectsMyAppFolder 
    
    npm install -g nexe
    // specify all the files you want to include inside the exe file
     nexe start.js -r "config.js" -r "nexe.config.js" -r "routes/common/oauth.js" -r "routes/*.js" -r "public//." -r ".vscode/**/." -r "package-lock.json" -r "package.json" --build --output "AppName.exe"
    

  2. Author of the tutorial here 🙂

    I’m not sure how nexe works exactly but please note that the sample app expects input parameters such as FORGE_CLIENT_ID or FORGE_CLIENT_SECRET to be provided as environment variables.

    As a first step, try running your *.exe file after setting the env. variables in your command prompt.

    If that doesn’t work, try hard-coding the input parameters directly into the config.js file (replacing any of the process.env.* references), and then bundle everything into an *.exe file. This is just for debugging purposes, though! You shouldn’t share your credentials with anyone, not even inside an *.exe file. So as an alternative I’d suggest that you update the sample app to read the input parameters from somewhere else, perhaps from a local file.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search