const http = require('http');
const https = require('https');
const http2 = require('http2');
const s = http.createServer((req, res) => { });
s.listen(PORT, ADDRESS);
const options = {key: KEY, cert: CERT};
const stls = https.createServer(options, (req, res) => { });
stls.listen(PORT_TLS, ADDRESS);
const s2 = http2.createSecureServer(options, (req, res) => { });
s2.listen(PORT_HTTP2, ADDRESS);
package main
import "net/http"
func main() {
s := &http.Server{Addr:"ADDRESS:PORT"}
s.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { })
go func() {
s.ListenAndServe()
}()
stls := &http.Server{Addr:"ADDRESS:PORT_TLS"}
stls.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { })
go func() {
stls.ListenAndServeTLS()
}()
// wait forever
select{ }
}
Analagous to readFileSync()
and Node.js.
import { createServer, createTLSServer, createSecureServer } from "deno";
const options = {key: KEY, cert: CERT};
const s = createServer((req, res) => { });
const stls = createTLSServer(options, (req, res) => { });
const s2 = createSecureServer(options, (req, res) => { });
s.listen(PORT, ADDRESS);
stls.listen(PORT_TLS, ADDRESS);
s2.listen(PORT_HTTP2, ADDRESS);
Distinct listen()
methods.
import { createServer } from "deno";
const options = {key: KEY, cert: CERT};
const s = createServer(options, (req, res) => { });
s.listen(PORT, ADDRESS);
s.listenTLS(PORT_TLS, ADDRESS);
s.listen2(PORT_HTTP2, ADDRESS);
Explicit constructors and flat namespace.
import { createHTTPServer, createTLSServer, createHTTP2Server } from "deno";
const options = {key: KEY, cert: CERT};
const s = createHTTPServer((req, res) => { });
const stls = createTLSServer(options, (req, res) => { });
const s2 = createHTTP2Server(options, (req, res) => { });
s.listen(PORT, ADDRESS);
stls.listen(PORT_TLS, ADDRESS);
s2.listen(PORT_HTTP2, ADDRESS);
Node.js-like namespaces to disambiguate createServer()
.
import { http, https, http2 } from "deno";
const options = {key: KEY, cert: CERT};
const s = http.createServer((req, res) => { });
const stls = https.createServer(options, (req, res) => { });
const s2 = http2.createServer(options, (req, res) => { });
s.listen(PORT, ADDRESS);
stls.listen(PORT_TLS, ADDRESS);
s2.listen(PORT_HTTP2, ADDRESS);
createServer()
attribute.
import { createServer } from "deno";
const options = {key: KEY, cert: CERT};
const s = createServer((req, res) => { });
const stls = createServer({...options, protocol: "https"}, (req, res) => { });
const s2 = createServer({...options, protocol: "http/2"}, (req, res) => { });
s.listen(PORT, ADDRESS)
stls.listen(PORT_TLS, ADDRESS)
s2.listen(PORT_HTTP2, ADDRESS)
listen()
method argument.
import { createServer } from "deno";
const options = {key: KEY, cert: CERT};
const s = createServer(options, (req, res) => { });
s.listen(PORT, ADDRESS, "http");
s.listen({protocol: "https"}, PORT_TLS, ADDRESS);
s.listen({protocol: "http/2"}, PORT_HTTP2, ADDRESS);
listen() port map
import { createServer } from "deno";
const options = {key: KEY, cert: CERT};
const s = createServer(options, (req, res) => { });
const portMap = {80:"http", 443:["https", "http/2"]};
s.listen(portMap, ADDRESS);