I need to use SSL on my site in some cases,
/ P>
is required ('campus'). CreateServer ({key: fs.readFileSync ('/ tmp / tls.key'). ToString (), cert: fs.readFileSync ('/ tmp /tls.cert'). ToString ()});
My server.js is
#! / Usr / bin / env node var fs = require ('fs'); / ** * Server module export method Return new examples of application * * @ Ultimate {object} parameter - Complex / Express webserver initialization parameter * @ Return compandezes powered Express webserver * / var app = module.export = function getServerInstance (parameter) { Params = params || {}; // Specify the current DIR as the basic root of the server parameters .root = params.root || __dirname; Params ["key"] = fs.readFileSync ('/ tmp / tls.key'). ToString (); Params ["certificate"] = fs.readFileSync ('/ tmp / tls.cert'). ToString (); Requires return ('campus'). Create server (parameter); }; If (! Module.parent) {var port = process.env.PORT || 3000; Var host = process.env.HOST || '0.0.0.0'; Var server = app (); Server.listen (Port, Host, Function () {listening compound server at% s console.log (% s in% s environment), Host, Port, Server .set ('NV'))}) ; }
The problem is that I can not find http, https only if I just put my certificate and key inside the configuration folder and
* * Var app = module.exports = function getServerInstance (params) {params = params || {}; // Specify the current DIR as the basic root of the server parameters .root = params.root || __dirname; Requires return ('campus'). Create server (parameter); };
Then I get some error
config / tls.cert: 1 tion (export, requirement, module, __philename, __ dennaam) {- --- BEGIN CERTIFICAT ^^^^^^^^^^^ Syntax Error: Unexpected identifier on Module._compile (module .js: 439: 25)
What is Compoundjs to HTTPS And the fastest and easiest way to support http routes is, do I need two servers (like you often express straight away)?
Yes - you have two servers, such as with Express
var app = module Exports = function getServerInstance (parameter) {params = params || {}; // Specify the current DIR as the basic root of the server parameters .root = params.root || __dirname; Requires return ('campus'). Create server (parameter); }; Var port = process.env.PORT || 80; Var host = process.env.HOST || '0.0.0.0'; Var port_ https = 443; Var server = app (); Server.listen (port, host, function {server.set ("confvar", process.env.SERVER_NAME); console.log (listening compound server at '% s:% d in% s environment', host , Port, server.set ('env'));}); If (fs.existsSync (the key goes to the path here)) {var apphttps = module.exports = function getServerInstance (params) {params = params || {}; // Specify the current DIR as the basic root of the server parameters .root = params.root || __dirname; Params.key = fs.readFileSync (The path goes to the main here) .ststring (); Params.cert = fs.readFileSync (path to CERT goes here) .toString (); Requires return ('campus'). Create server (parameter); }; Var server https = apphttps (); Serverhttps.listen (port_https, host, function () {serverhttps.set ("confvar", process.env.SERVER_NAME); console.log ('% s listening to compound https server:% d in% s environment', Host, port_https, serverhttps.set ('env'));}); }
Comments
Post a Comment