Skip to content

Commit

Permalink
Merge pull request #357 from apex/nodejs43
Browse files Browse the repository at this point in the history
add nodejs 4.3.2 support. Closes #356
  • Loading branch information
tj committed Apr 8, 2016
2 parents 17baff5 + 1b37b3b commit 0385165
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion plugins/inference/inference.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func init() {
function.RegisterPlugin("inference", &Plugin{
Files: map[string]string{
"main.py": python.Runtime,
"index.js": nodejs.Runtime,
"index.js": nodejs.Runtime43,
"main.go": golang.Runtime,
"target/apex.jar": java.Runtime,
"build/libs/apex.jar": java.Runtime,
Expand Down
23 changes: 15 additions & 8 deletions plugins/nodejs/nodejs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@ import (
"github.com/apex/apex/plugins/env"
)

const (
// Runtime name used by Apex and by AWS Lambda for Node.js 0.10
Runtime = "nodejs"
// Runtime43 name used by Apex and by AWS Lambda for Node.js 4.3.2
Runtime43 = "nodejs4.3"
)

func init() {
function.RegisterPlugin("nodejs", &Plugin{})
function.RegisterPlugin(Runtime, &Plugin{})
function.RegisterPlugin(Runtime43, &Plugin{})
}

// prelude script template.
Expand All @@ -30,17 +38,12 @@ var prelude = template.Must(template.New("prelude").Parse(`try {
exports.handle = require('./{{.HandleFile}}').{{.HandleMethod}}
`))

const (
// Runtime name used by Apex and by AWS Lambda
Runtime = "nodejs"
)

// Plugin implementation.
type Plugin struct{}

// Open adds nodejs defaults.
func (p *Plugin) Open(fn *function.Function) error {
if fn.Runtime != Runtime {
if !p.runtimeSupported(fn) {
return nil
}

Expand All @@ -53,7 +56,7 @@ func (p *Plugin) Open(fn *function.Function) error {

// Build injects a script for loading the environment.
func (p *Plugin) Build(fn *function.Function, zip *archive.Archive) error {
if fn.Runtime != Runtime || len(fn.Environment) == 0 {
if !p.runtimeSupported(fn) || len(fn.Environment) == 0 {
return nil
}

Expand Down Expand Up @@ -81,3 +84,7 @@ func (p *Plugin) Build(fn *function.Function, zip *archive.Archive) error {

return zip.AddBytesMTime("_apex_index.js", buf.Bytes(), time.Unix(0, 0))
}

func (p *Plugin) runtimeSupported(fn *function.Function) bool {
return fn.Runtime == Runtime || fn.Runtime == Runtime43
}

0 comments on commit 0385165

Please sign in to comment.