Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow running functions in node18 #769

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions cmd/dev/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ const (
flagsFunctionsPort = "functions-port"
flagsHasuraPort = "hasura-port"
flagsHasuraConsolePort = "hasura-console-port"
flagsNode18 = "node18"
)

const (
defaultHTTPPort = 443
defaultPostgresPort = 5432
)

func CommandUp() *cli.Command {
func CommandUp() *cli.Command { //nolint:funlen
return &cli.Command{ //nolint:exhaustruct
Name: "up",
Aliases: []string{},
Expand Down Expand Up @@ -88,6 +89,11 @@ func CommandUp() *cli.Command {
Usage: "If specified, expose hasura console on this port. Not recommended",
Value: 0,
},
&cli.BoolFlag{ //nolint:exhaustruct
Name: flagsNode18,
Usage: "Use node 18. Defaults to node 16",
Value: false,
},
},
}
}
Expand Down Expand Up @@ -123,6 +129,7 @@ func commandUp(cCtx *cli.Context) error {
Console: cCtx.Uint(flagsHasuraConsolePort),
Functions: cCtx.Uint(flagsFunctionsPort),
},
cCtx.Bool(flagsNode18),
)
}

Expand Down Expand Up @@ -180,6 +187,7 @@ func up( //nolint:funlen
postgresPort uint,
applySeeds bool,
ports dockercompose.ExposePorts,
useNode18 bool,
) error {
ctx, cancel := context.WithCancel(ctx)

Expand Down Expand Up @@ -207,6 +215,7 @@ func up( //nolint:funlen
ce.Path.DotNhostFolder(),
ce.Path.Root(),
ports,
useNode18,
)
if err != nil {
return fmt.Errorf("failed to generate docker-compose.yaml: %w", err)
Expand Down Expand Up @@ -278,11 +287,12 @@ func Up(
postgresPort uint,
applySeeds bool,
ports dockercompose.ExposePorts,
useNode18 bool,
) error {
dc := dockercompose.New(ce.Path.WorkingDir(), ce.Path.DockerCompose(), ce.ProjectName())

if err := up(
ctx, ce, dc, httpPort, useTLS, postgresPort, applySeeds, ports,
ctx, ce, dc, httpPort, useTLS, postgresPort, applySeeds, ports, useNode18,
); err != nil {
ce.Warnln(err.Error())

Expand Down
11 changes: 10 additions & 1 deletion dockercompose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ func functions( //nolint:funlen
rootFolder string,
jwtSecret string,
port uint,
useNode18 bool,
) *Service {
envVars := map[string]string{
"HASURA_GRAPHQL_ADMIN_SECRET": cfg.Hasura.AdminSecret,
Expand All @@ -317,8 +318,14 @@ func functions( //nolint:funlen
for _, envVar := range cfg.GetGlobal().GetEnvironment() {
envVars[envVar.GetName()] = envVar.GetValue()
}

image := "nhost/functions:0.1.9"
if useNode18 {
image = "nhost/functions:1.0.0"
}

return &Service{
Image: "nhost/functions:0.1.9",
Image: image,
DependsOn: nil,
EntryPoint: nil,
Command: nil,
Expand Down Expand Up @@ -427,6 +434,7 @@ func ComposeFileFromConfig( //nolint:funlen
dotNhostFolder string,
rootFolder string,
ports ExposePorts,
useNode18 bool,
) (*ComposeFile, error) {
minio, err := minio(dataFolder)
if err != nil {
Expand Down Expand Up @@ -482,6 +490,7 @@ func ComposeFileFromConfig( //nolint:funlen
rootFolder,
jwtSecret,
ports.Functions,
useNode18,
),
"graphql": graphql,
"minio": minio,
Expand Down
4 changes: 3 additions & 1 deletion examples/myproject/functions/echo.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Request, Response } from 'express'
import process from 'process'

export default (req: Request, res: Response) => {
res.status(539).json(
res.status(200).json(
{
headers: req.headers,
query: req.query,
node: process.version,
},
)
}
2 changes: 1 addition & 1 deletion examples/myproject/nhost/nhost.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ timeout = 60000
enabled = false

[postgres]
version = '14.6-20230406-1'
version = '14.6-20230705-1'

[provider]

Expand Down
5 changes: 5 additions & 0 deletions examples/myproject/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.