ericmdantas / generator-ng-fullstack

Client, server or fullstack - it's up to you. ng-fullstack gives you the best of the latest.
MIT License
704 stars 103 forks source link

Implement http2 server #96

Closed ericmdantas closed 8 years ago

ericmdantas commented 8 years ago
ericmdantas commented 8 years ago

Go server:

package main

import (
    "fmt"
    "net/http"

    "golang.org/x/net/http2"
)

func main() {
    var srv http.Server
    http2.VerboseLogs = true
    srv.Addr = ":3333"
    http2.ConfigureServer(&srv, nil)

    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte("yo!"))
    })

    log.Fatal(srv.ListenAndServeTLS("crt/server.crt", "crt/server.key"))
}
ericmdantas commented 8 years ago

Node server:

const express = require('express');
const http2 = require('http2');

const app = express();

app.get('/', (req, res) => {
  res.end("yo!");
});

var options = {
  key: fs.readFileSync('./crt/localhost.key'),
  cert: fs.readFileSync('./crt/localhost.crt')
};

http2.createServer(options, app)
     .listen(3333, () => {
        console.log('server up');
     });
ericmdantas commented 8 years ago

Welp, looks like express and the http2 module don't get along yet: https://github.com/molnarg/node-http2/issues/100

ericmdantas commented 8 years ago

Since there's the bug above, node will have to stay with https for now.

ericmdantas commented 8 years ago

As a note, Node servers will have to have its files copied like go's, see here: https://github.com/ericmdantas/generator-ng-fullstack/blob/master/_ng/server/go.js#L39

ericmdantas commented 8 years ago

Done.

ericmdantas commented 8 years ago

Important for node/express: https://github.com/expressjs/express/issues/2761#issuecomment-221675351