https#ServerOptions TypeScript Examples

The following examples show how to use https#ServerOptions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: connect.ts    From clearflask with Apache License 2.0 6 votes vote down vote up
sniCallback: ServerOptions['SNICallback'] = async (servername, callback) => {
  // Get cert
  const wildName = '*.' + servername
    .split('.')
    .slice(1)
    .join('.');
  var secureContext: SecureContext = secureContextCache.get(servername) || secureContextCache.get(wildName);
  if (!secureContext) {
    var certAndKey: CertGetOrCreateResponse;
    try {
      certAndKey = await ServerConnect.get()
        .dispatch()
        .certGetOrCreateConnect(
          { domain: servername },
          undefined,
          { 'x-cf-connect-token': connectConfig.connectToken });
      console.log('Found cert for servername', servername);
    } catch (response: any) {
      console.log('Cert get unknown error for servername', servername, response);
      callback(new Error('No certificate found'), null as any);
      return;
    }

    // Create secure context
    secureContext = tls.createSecureContext({
      key: certAndKey.keypair.privateKeyPem,
      cert: certAndKey.cert.cert + "\n" + certAndKey.cert.chain,
    });

    // Add to cache
    const expiresInSec = certAndKey.cert.expiresAt - new Date().getTime();
    [servername, ...certAndKey.cert.altnames].forEach(altName => secureContextCache.set(
      servername,
      secureContext,
      Math.min(3600, expiresInSec)));
  }

  callback(null, secureContext);
}
Example #2
Source File: classes.ts    From epicgames-freegames-node with MIT License 5 votes vote down vote up
/**
   * Node HTTPS.createServer options: https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener
   */
  @IsOptional()
  @IsObject()
  serverOpts?: ServerOptions;
Example #3
Source File: server.ts    From elemental4 with GNU General Public License v3.0 5 votes vote down vote up
export function serverCreate() {
    app = express();
    io = SocketIO();
    io.origins('*:*');

    newEntryEmitter.on((entry) => {
        io.sockets.emit('new-entry', entry)
    })
        
    // Remove Express Header
    app.use((req,res,next) => {
        res.removeHeader("X-Powered-By");
        res.setHeader("Access-Control-Allow-Origin", "*");
        res.setHeader("Access-Control-Allow-Headers", "*");
        res.setHeader("Access-Control-Expose-Headers", "Content-Length,Elem4-Entry-Length");

        next();
    });

    app.get('/', (r,res) => res.send("Elemental 4 " + pkg.version));
    app.get('/ping', (r,res) => res.send("pong"));
    app.get('/elemental.json', (r,res) => {
        res.send({
            type: 'elemental4',
            name: SERVER_NAME,
            description: SERVER_DESCRIPTION,
            serverVersion: pkg.version,
            icon: SERVER_ICON,
            dbId: getDbId()
        })
    });
    
    // Add api calls
    app.use(require("./api/api-v1").default());

    // Create an HTTP service.
    if (ENABLE_HTTP) {
        if(ENABLE_HTTPS) {
            // redirectify
            createHTTPServer((req, res) => {
                const host = req.headers["host"];
                const url = "https://" + host + req.url;
                res.statusCode = 302;
                res.setHeader("Location", url);
                res.end("Moved to <a href='" + url + "'>" + url + "</a>");
            }).listen(HTTP_PORT, () => {
                log.info("HTTP server started (Redirecting to HTTPS). http://localhost:" + HTTP_PORT);
            });
        } else {
            // make the server on http
            const s = createHTTPServer(app).listen(HTTP_PORT, () => {
                log.info("HTTP server started. http://localhost:" + HTTP_PORT);
            });
            io.listen(s);
        }
    }
    
    // Create an HTTPS service identical to the HTTP service.
    if (ENABLE_HTTPS) {
        const httpsOptions: ServerOptions = {
            key: readFileSync(HTTPS_KEY),
            cert: readFileSync(HTTPS_CERT),
        }
        const s = createHTTPSServer(httpsOptions, app).listen(HTTPS_PORT, () => {
            log.info("HTTPS server started. https://localhost:" + HTTPS_PORT);
        });
        io.listen(s);
    }
}