Javascript 节点-使用https模块和ngrok服务静态文件

Javascript 节点-使用https模块和ngrok服务静态文件,javascript,node.js,express,https,Javascript,Node.js,Express,Https,通过这个简单的cli脚本,我试图生成一个子进程,该子进程将运行服务器并打开一个ngrok隧道。管理子进程spawn的类将正常工作。我想为vue应用程序前端提供一个静态index.html文件。目前我正在使用此代码,但: 如何用内置的https模块替换express,以避免ngrok隧道出现CORS问题?我已经阅读了关于节点的文档,由于潜在的安全问题,使用fs.readFile或fs.readFileSync来提供静态文件是个坏主意 由于我在CLI脚本中,如果用作项目依赖项,是否可以使用expr

通过这个简单的cli脚本,我试图生成一个子进程,该子进程将运行服务器并打开一个ngrok隧道。管理子进程spawn的类将正常工作。我想为vue应用程序前端提供一个静态index.html文件。目前我正在使用此代码,但:

  • 如何用内置的
    https
    模块替换express,以避免ngrok隧道出现CORS问题?我已经阅读了关于节点的文档,由于潜在的安全问题,使用
    fs.readFile
    fs.readFileSync
    来提供静态文件是个坏主意

  • 由于我在CLI脚本中,如果用作项目依赖项,是否可以使用express overkill

  • //index.js文件cli入口点
    #!/usr/bin/env节点
    const path=require('path');
    const{ProcessSpinner}=require('./ProcesSpinner');
    log(“脚本已启动”);
    const serverScript=path.format({dir:uu dirname,base:'cli.js'});
    const main=新的ProcessSpinner(serverScript);
    main.initScript();
    //我的类ProcessSpinner.js
    const spawn=require('child_process')。spawn;
    类进程微调器{
    建造师(资源){
    this.resource=String(资源);
    }
    initScript(){
    this.exploit=spawn(process.execPath,[this.resource]{
    stdin:process.stdin,
    stdio:process.stdio,
    //环境:{
    //     '': 
    // }
    });
    console.log(this.exploit);
    }
    stopScript(){
    this.exploit.kill();
    }
    }
    exports.ProcessSpinner=ProcessSpinner;
    //cli.js
    常数fs=要求('fs');
    const path=require('path');
    //常量https=require('https');
    const express=require('express');
    常量app=express();
    const ngork=require('ngrok');
    use(express.static(path.format({dir:u dirname,base:'index.html'}));
    应用程序获取(“/”,(请求,请求)=>{
    书面记录(200);
    res.sendFile(path.format({dir:uu dirname,base:'index.html'}));
    });
    app.listen(6780,()=>console.log('服务器启动于http://localhost:6880') );
    连接({proto:'http',端口:6780})。然后((url)=>{
    log('在以下位置创建的隧道',url);
    }).catch((错误)=>{
    console.log(错误);
    });