diff --git a/.github/workflows/pr-node-tests.yml b/.github/workflows/pr-node-tests.yml index 5144527..81ee1df 100644 --- a/.github/workflows/pr-node-tests.yml +++ b/.github/workflows/pr-node-tests.yml @@ -19,9 +19,11 @@ jobs: - examples/18 - examples/19 - examples/20 + - examples/21 + - examples/22 + - examples/23 lando-version: - 3-edge - - 3-stable os: - ubuntu-24.04 node-version: diff --git a/CHANGELOG.md b/CHANGELOG.md index 00cd906..f59eec2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## {{ UNRELEASED_VERSION }} - [{{ UNRELEASED_DATE }}]({{ UNRELEASED_LINK }}) +* Added support for Node 23, 22 and 21. [#92](https://github.com/lando/node/issues/92) + ## v1.3.3 - [December 6, 2024](https://github.com/lando/node/releases/tag/v1.3.3) * Updated the version index.md to get Docuverse page to build correctly. diff --git a/builders/node.js b/builders/node.js index f1a0d63..997ff28 100644 --- a/builders/node.js +++ b/builders/node.js @@ -5,6 +5,33 @@ const _ = require('lodash'); // Constants const supportedVersions = [ + '23', + '23.5', + '23.4', + '23.3', + '23.2', + '23.1', + '22', + '22.12', + '22.11', + '22.10', + '22.9', + '22.8', + '22.7', + '22.6', + '22.5', + '22.4', + '22.3', + '22.2', + '22.1', + '21', + '21.7', + '21.6', + '21.5', + '21.4', + '21.3', + '21.2', + '21.1', '20', '20.9', '20.8', diff --git a/docs/caveats.md b/docs/caveats.md index b3eeae7..cdba8f1 100644 --- a/docs/caveats.md +++ b/docs/caveats.md @@ -21,4 +21,4 @@ Lando will set the `PATH` hierarchy for this service as follows: ] ``` -This is useful to note if you are not using absolute paths in any [tooling routes](https://docs.lando.dev/core/v3/tooling.html) and are getting the unexpected version of a particular utility. +This is useful to note if you are not using absolute paths in any [tooling routes](https://docs.lando.dev/landofile/tooling.html) and are getting the unexpected version of a particular utility. diff --git a/docs/config.md b/docs/config.md index 35854aa..d925ef6 100644 --- a/docs/config.md +++ b/docs/config.md @@ -5,9 +5,9 @@ description: Learn how to configure the Lando Node service. # Configuration -Here are the configuration options, set to the default values, for this service. If you are unsure about where this goes or what this means, we *highly recommend* scanning the [services documentation](https://docs.lando.dev/core/v3/services/lando.html) to get a good handle on how the magicks work. +Here are the configuration options, set to the default values, for this service. If you are unsure about where this goes or what this means, we *highly recommend* scanning the [services documentation](https://docs.lando.dev/services/lando-3.html) to get a good handle on how the magicks work. -Also note that options, in addition to the [build steps](https://docs.lando.dev/core/v3/services/lando.html#build-steps) and [overrides](https://docs.lando.dev/core/v3/services/lando.html#overrides) that are available to every service, are shown below: +Also note that options, in addition to the [build steps](https://docs.lando.dev/services/lando-3.html#build-steps) and [overrides](https://docs.lando.dev/services/lando-3.html#overrides) that are available to every service, are shown below: ```yaml services: @@ -47,7 +47,7 @@ services: ## Using SSL -Also note that `ssl: true` will only generate certs in the [default locations](https://docs.lando.dev/core/v3/security.html) and expose port `443`. It is up to the user to use the certs and secure port correctly in their application like the `node` snippet below: +Also note that `ssl: true` will only generate certs in the [default locations](https://docs.lando.dev/config/security.html) and expose port `443`. It is up to the user to use the certs and secure port correctly in their application like the `node` snippet below: ```js // Get our key and cert @@ -80,9 +80,9 @@ services: You can also use the `globals` key if you need to install any [global node dependencies](https://docs.npmjs.com/cli/install/). This follows the same syntax as your normal [`package.json`](https://docs.npmjs.com/files/package.json/) except written as YAML instead of JSON. ::: tip Use package.json if you can! -While there are some legitimate use cases to globally install a node dependency, it is almost always preferred to install using your applications normal `package.json` and then running either `lando npm` or `lando yarn` or alternatively setting up a [build step](https://docs.lando.dev/core/v3/services/lando.html#build-steps) that will automatically run before your app starts up. +While there are some legitimate use cases to globally install a node dependency, it is almost always preferred to install using your applications normal `package.json` and then running either `lando npm` or `lando yarn` or alternatively setting up a [build step](https://docs.lando.dev/services/lando-3.html#build-steps) that will automatically run before your app starts up. -Note that both `lando yarn` and `lando npm` are not provided out of the box by the `node` service and need to be manually added by configuring your app's [tooling](https://docs.lando.dev/core/v3/tooling.html). +Note that both `lando yarn` and `lando npm` are not provided out of the box by the `node` service and need to be manually added by configuring your app's [tooling](https://docs.lando.dev/landofile/tooling.html). ::: An example of globally installing the `latest` `gulp-cli` is shown below: @@ -96,7 +96,7 @@ services: command: npm start ``` -An example of using a [build step](https://docs.lando.dev/core/v3/services/lando.html#build-steps) to automatically `npm install` your dependencies before your app invokes `yarn start-app` is shown below: +An example of using a [build step](https://docs.lando.dev/services/lando-3.html#build-steps) to automatically `npm install` your dependencies before your app invokes `yarn start-app` is shown below: ```yaml services: @@ -127,7 +127,7 @@ lando node lando yarn ``` -Lando tooling is actually pretty powerful so definitely check out [the rest](https://docs.lando.dev/core/v3/tooling.html) of its cool features. +Lando tooling is actually pretty powerful so definitely check out [the rest](https://docs.lando.dev/landofile/tooling.html) of its cool features. ## Adding routing @@ -140,4 +140,4 @@ proxy: - something.else.local ``` -Lando proxying is actually pretty powerful so definitely check out [the rest](https://docs.lando.dev/core/v3/proxy.html) of its cool features. +Lando proxying is actually pretty powerful so definitely check out [the rest](https://docs.lando.dev/landofile/proxy.html) of its cool features. diff --git a/docs/guides/frontend-tooling.md b/docs/guides/frontend-tooling.md index a0fa54d..5872f9c 100644 --- a/docs/guides/frontend-tooling.md +++ b/docs/guides/frontend-tooling.md @@ -23,7 +23,7 @@ When you're done, you should be able to distribute your Lando app with a full se ## Add Node Service -Assuming you're starting with a "Lando-ized" app, open the `.lando.yml` file in the root of your app directory. In this example we'll assume you're using a very basic [LAMP](https://docs.lando.dev/core/v3/lamp.html) recipe. +Assuming you're starting with a "Lando-ized" app, open the `.lando.yml` file in the root of your app directory. In this example we'll assume you're using a very basic [LAMP](https://docs.lando.dev/plugins/lamp/) recipe. To install our frontend tooling we need to be able to run Node. Fortunately it's very easy for us to add a basic Node service to our app: @@ -61,12 +61,12 @@ You can do the same thing for any NPM project; for example Grunt would be `grunt Note we've now added a another command to `build` to automatically run `gulp` every time we start the app. This, of course, assumes that the default `gulp` task is defined otherwise you should expect your build step to fail. ::: tip Package Versions Are Fully Armed and Customizable -You can lock your app tooling to whatever package version you like. Don't use node:6.10? Change to one of the other available versions in the [service documentation](https://docs.lando.dev/core/v3/node.html). And you're free to download whatever version of a global service your heart desires. For example, if you want to lock your team to something more stable than the latest gulp-cli, change that entry in `globals` to `gulp-cli:1.3.0`. +You can lock your app tooling to whatever package version you like. Don't use node:6.10? Change to one of the other available versions in the [service documentation](https://docs.lando.dev/plugins/node/). And you're free to download whatever version of a global service your heart desires. For example, if you want to lock your team to something more stable than the latest gulp-cli, change that entry in `globals` to `gulp-cli:1.3.0`. ::: ## Making Tooling Available on the CLI -Almost there! All our services are installed, but how do we run a command on the fly, say starting a watch task or running `lando npm install hot-new-thing` to start experimenting with a new package? We could SSH into our node container, but that's SO 2016. Instead, we'll expose our new tooling via the CLI by adding this [`tooling`](https://docs.lando.dev/core/v3/tooling.html) section to our `.lando.yml` file: +Almost there! All our services are installed, but how do we run a command on the fly, say starting a watch task or running `lando npm install hot-new-thing` to start experimenting with a new package? We could SSH into our node container, but that's SO 2016. Instead, we'll expose our new tooling via the CLI by adding this [`tooling`](https://docs.lando.dev/landofile/tooling.html) section to our `.lando.yml` file: ```yml tooling: diff --git a/docs/guides/using-compass.md b/docs/guides/using-compass.md index 3c940b4..91fd436 100644 --- a/docs/guides/using-compass.md +++ b/docs/guides/using-compass.md @@ -23,7 +23,7 @@ However, if you cannot do this you may run into some issues running `compass` in You can, however, get around it by installing `ruby` and `compose` directly in the `node` service that requires them. -Below is an example that installs `ruby` and `compass` using [build-steps](https://docs.lando.dev/core/v3/services/lando.html#build-steps). +Below is an example that installs `ruby` and `compass` using [build-steps](https://docs.lando.dev/services/lando-3.html#build-steps). ```yaml services: diff --git a/docs/index.md b/docs/index.md index 8883969..f84f7e9 100644 --- a/docs/index.md +++ b/docs/index.md @@ -8,7 +8,7 @@ next: ./config.html [Node.js](https://nodejs.org/en/) is a JavaScript runtime built on Chrome's V8 JavaScript engine and uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Beyond running web applications, it is also commonly used for frontend tooling. -You can easily add it to your Lando app by adding an entry to the [services](https://docs.lando.dev/core/v3/services/lando.html) top-level config in your [Landofile](https://docs.lando.dev/core/v3). +You can easily add it to your Lando app by adding an entry to the [services](https://docs.lando.dev/services/lando-3.html) top-level config in your [Landofile](https://docs.lando.dev/landofile/). ```yaml services: @@ -19,6 +19,9 @@ services: ## Supported versions +* [23](https://hub.docker.com/_/node) +* [22](https://hub.docker.com/_/node) +* [21](https://hub.docker.com/_/node) * [20](https://hub.docker.com/_/node) * [19](https://hub.docker.com/_/node) * [18](https://hub.docker.com/_/node) @@ -26,7 +29,7 @@ services: * [16](https://hub.docker.com/_/node) * [15](https://hub.docker.com/_/node) * **[14](https://hub.docker.com/_/node)** **(default)** -* [custom](https://docs.lando.dev/core/v3/services/lando.html#overrides) +* [custom](https://docs.lando.dev/services/lando-3.html#overrides) ## Legacy versions diff --git a/examples/21/.gitignore b/examples/21/.gitignore new file mode 100644 index 0000000..740a0a4 --- /dev/null +++ b/examples/21/.gitignore @@ -0,0 +1,3 @@ +node_modules +*.log +package-lock.json diff --git a/examples/21/.lando.yml b/examples/21/.lando.yml new file mode 100644 index 0000000..f69383f --- /dev/null +++ b/examples/21/.lando.yml @@ -0,0 +1,37 @@ +name: lando-node-21 +services: + defaults: + type: node:21 + build: + - yarn + command: /app/node_modules/.bin/nodemon src/app-http.js --watch src --ignore *.test.js + cli: + type: node + compass: + type: node:21 + globals: + grunt-cli: latest + custom: + type: node:21 + ssl: true + globals: + gulp-cli: latest + port: 3000 + build: + - yarn + command: /app/node_modules/.bin/nodemon src/app-https.js --watch src --ignore *.test.js + custom2: + type: node:21.5.0 + ssl: 4444 + port: 3000 + build: + - yarn + command: /app/node_modules/.bin/nodemon src/app-custom.js --watch src --ignore *.test.js +tooling: + grunt: + service: compass + +# This is important because it lets lando know to test against the plugin in this repo +# DO NOT REMOVE THIS! +plugins: + "@lando/node": ../.. diff --git a/examples/21/README.md b/examples/21/README.md new file mode 100644 index 0000000..c881fed --- /dev/null +++ b/examples/21/README.md @@ -0,0 +1,83 @@ +# Node 21 Example + +This example exists primarily to test the following documentation: + +* [Node 14-21 Service](https://docs.devwithlando.io/tutorials/node.html) +* [Installing compass in your node service](https://docs.lando.dev/guides/using-compass-on-a-lando-node-service.html) + +## Start up tests + +Run the following commands to get up and running with this example. + +```bash +# Should start up successfully +lando poweroff +lando start +``` + +## Verification commands + +Run the following commands to validate things are rolling as they should. + +```bash +# Should use 21.x as the default version +lando exec defaults -- "env | grep NODE_VERSION=21." + +# Should use a user specified version if given +lando exec custom -- "env | grep NODE_VERSION=21." + +# Should use a user specified patch version if given +lando exec custom2 -- "env | grep NODE_VERSION=21.5.0" + +# Should serve over port 80 by default +lando exec defaults -- "curl http://localhost | grep tune" + +# Should set NODE_EXTRA_CA_CERTS with lando domain CA +lando exec defaults -- "env" | grep NODE_EXTRA_CA_CERTS | grep "$LANDO_CA_CERT" + +# Should only serve over http by default +lando exec defaults -- "curl https://localhost" || echo $? | grep 7 + +# Should serve over specified ports if given +lando exec custom -- "curl http://localhost:3000 | grep tune" + +# Should serve over https is ssl is set by user +lando exec custom -- "curl https://localhost | grep tune" + +# Should servce over a custom https port if ssl is set to a specific port +lando exec custom2 -- "curl https://localhost:4444 | grep DANCING" + +# Should run as root if it needs to +lando exec defaults -- "ps -a -u root" | grep "node" | wc -l | grep 2 +lando exec custom -- "ps -a -u root" | grep "node" | wc -l | grep 2 + +# Should run as node if it can +lando exec custom2 -- "ps -a -u node" | grep "node" | wc -l | grep 2 + +# Should install global dependencies if specified by user and have them available in PATH +lando exec custom -- "gulp -v" +lando exec custom -- "which gulp | grep /var/www/.npm-global" + +# Should PATH prefer node dependency binaries installed in /app/node_modules over global ones +lando exec custom -- "npm install gulp-cli --no-save" +lando exec custom -- "gulp -v" +lando exec custom -- "which gulp | grep /app/node_modules/.bin" +lando exec custom -- "npm uninstall gulp-cli" +lando exec custom -- "which gulp | grep /var/www/.npm-global" + +# Should not serve port for cli +lando exec cli -- "curl http://localhost" || echo $? | grep 7 + +# Should install gruntcli +lando grunt -V +``` + +## Destroy tests + +Run the following commands to trash this app like nothing ever happened. + +```bash +# Should be destroyed with success +lando destroy -y +lando poweroff +``` diff --git a/examples/21/package.json b/examples/21/package.json new file mode 100644 index 0000000..7f9f428 --- /dev/null +++ b/examples/21/package.json @@ -0,0 +1,27 @@ +{ + "name": "node-lando", + "version": "1.0.0", + "description": "Node example for Lando", + "main": "app.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://github.com/lando/lando/tree/master/examples/node" + }, + "keywords": [ + "node", + "docker", + "localdev" + ], + "author": "Mike Pirog", + "license": "MIT", + "dependencies": { + "express": "^4.19.2" + }, + "devDependencies": { + "grunt-contrib-compass": "^1.1.1", + "nodemon": "^3.0.1" + } +} diff --git a/examples/21/src/app-custom.js b/examples/21/src/app-custom.js new file mode 100644 index 0000000..b47fc14 --- /dev/null +++ b/examples/21/src/app-custom.js @@ -0,0 +1,28 @@ +/** + * Lando node express example + * + * @name taylorswift + */ + +'use strict'; + +// Load modules +const fs = require('fs'); +const http = require('http'); +const https = require('https'); +const express = require('express'); +const app = express(); + +// Create our HTTPS server options +const key = fs.readFileSync('/certs/cert.key'); +const cert = fs.readFileSync('/certs/cert.crt'); + +// Create our servers +https.createServer({key, cert}, app).listen(4444); +http.createServer(app).listen(3000); + +// Basic HTTP response +app.get('/', (req, res) => { + res.header('Content-type', 'text/html'); + return res.end('

DANCING DANCING STARLIGHT

'); +}); diff --git a/examples/21/src/app-http.js b/examples/21/src/app-http.js new file mode 100644 index 0000000..fe682e2 --- /dev/null +++ b/examples/21/src/app-http.js @@ -0,0 +1,21 @@ +/** + * Lando node express example + * + * @name taylorswift + */ + +'use strict'; + +// Load modules +const http = require('http'); +const express = require('express'); +const app = express(); + +// Create our server +http.createServer(app).listen(80); + +// Basic HTTP response +app.get('/', (req, res) => { + res.header('Content-type', 'text/html'); + return res.end('

I said "Oh my!" What a marvelous tune!!!

'); +}); diff --git a/examples/21/src/app-https.js b/examples/21/src/app-https.js new file mode 100644 index 0000000..84c81bf --- /dev/null +++ b/examples/21/src/app-https.js @@ -0,0 +1,28 @@ +/** + * Lando node express example + * + * @name taylorswift + */ + +'use strict'; + +// Load modules +const fs = require('fs'); +const http = require('http'); +const https = require('https'); +const express = require('express'); +const app = express(); + +// Create our HTTPS server options +const key = fs.readFileSync('/certs/cert.key'); +const cert = fs.readFileSync('/certs/cert.crt'); + +// Create our servers +https.createServer({key, cert}, app).listen(443); +http.createServer(app).listen(3000); + +// Basic HTTP response +app.get('/', (req, res) => { + res.header('Content-type', 'text/html'); + return res.end('

I said "Oh my!" What a marvelous tune!!!

'); +}); diff --git a/examples/22/.gitignore b/examples/22/.gitignore new file mode 100644 index 0000000..740a0a4 --- /dev/null +++ b/examples/22/.gitignore @@ -0,0 +1,3 @@ +node_modules +*.log +package-lock.json diff --git a/examples/22/.lando.yml b/examples/22/.lando.yml new file mode 100644 index 0000000..e890ff7 --- /dev/null +++ b/examples/22/.lando.yml @@ -0,0 +1,37 @@ +name: lando-node-22 +services: + defaults: + type: node:22 + build: + - yarn + command: /app/node_modules/.bin/nodemon src/app-http.js --watch src --ignore *.test.js + cli: + type: node + compass: + type: node:22 + globals: + grunt-cli: latest + custom: + type: node:22 + ssl: true + globals: + gulp-cli: latest + port: 3000 + build: + - yarn + command: /app/node_modules/.bin/nodemon src/app-https.js --watch src --ignore *.test.js + custom2: + type: node:22.7.0 + ssl: 4444 + port: 3000 + build: + - yarn + command: /app/node_modules/.bin/nodemon src/app-custom.js --watch src --ignore *.test.js +tooling: + grunt: + service: compass + +# This is important because it lets lando know to test against the plugin in this repo +# DO NOT REMOVE THIS! +plugins: + "@lando/node": ../.. diff --git a/examples/22/README.md b/examples/22/README.md new file mode 100644 index 0000000..3f51039 --- /dev/null +++ b/examples/22/README.md @@ -0,0 +1,83 @@ +# Node 22 Example + +This example exists primarily to test the following documentation: + +* [Node 14-22 Service](https://docs.devwithlando.io/tutorials/node.html) +* [Installing compass in your node service](https://docs.lando.dev/guides/using-compass-on-a-lando-node-service.html) + +## Start up tests + +Run the following commands to get up and running with this example. + +```bash +# Should start up successfully +lando poweroff +lando start +``` + +## Verification commands + +Run the following commands to validate things are rolling as they should. + +```bash +# Should use 22.x as the default version +lando exec defaults -- "env | grep NODE_VERSION=22." + +# Should use a user specified version if given +lando exec custom -- "env | grep NODE_VERSION=22." + +# Should use a user specified patch version if given +lando exec custom2 -- "env | grep NODE_VERSION=22.7.0" + +# Should serve over port 80 by default +lando exec defaults -- "curl http://localhost | grep tune" + +# Should set NODE_EXTRA_CA_CERTS with lando domain CA +lando exec defaults -- "env" | grep NODE_EXTRA_CA_CERTS | grep "$LANDO_CA_CERT" + +# Should only serve over http by default +lando exec defaults -- "curl https://localhost" || echo $? | grep 7 + +# Should serve over specified ports if given +lando exec custom -- "curl http://localhost:3000 | grep tune" + +# Should serve over https is ssl is set by user +lando exec custom -- "curl https://localhost | grep tune" + +# Should servce over a custom https port if ssl is set to a specific port +lando exec custom2 -- "curl https://localhost:4444 | grep DANCING" + +# Should run as root if it needs to +lando exec defaults -- "ps -a -u root" | grep "node" | wc -l | grep 2 +lando exec custom -- "ps -a -u root" | grep "node" | wc -l | grep 2 + +# Should run as node if it can +lando exec custom2 -- "ps -a -u node" | grep "node" | wc -l | grep 2 + +# Should install global dependencies if specified by user and have them available in PATH +lando exec custom -- "gulp -v" +lando exec custom -- "which gulp | grep /var/www/.npm-global" + +# Should PATH prefer node dependency binaries installed in /app/node_modules over global ones +lando exec custom -- "npm install gulp-cli --no-save" +lando exec custom -- "gulp -v" +lando exec custom -- "which gulp | grep /app/node_modules/.bin" +lando exec custom -- "npm uninstall gulp-cli" +lando exec custom -- "which gulp | grep /var/www/.npm-global" + +# Should not serve port for cli +lando exec cli -- "curl http://localhost" || echo $? | grep 7 + +# Should install gruntcli +lando grunt -V +``` + +## Destroy tests + +Run the following commands to trash this app like nothing ever happened. + +```bash +# Should be destroyed with success +lando destroy -y +lando poweroff +``` diff --git a/examples/22/package.json b/examples/22/package.json new file mode 100644 index 0000000..7f9f428 --- /dev/null +++ b/examples/22/package.json @@ -0,0 +1,27 @@ +{ + "name": "node-lando", + "version": "1.0.0", + "description": "Node example for Lando", + "main": "app.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://github.com/lando/lando/tree/master/examples/node" + }, + "keywords": [ + "node", + "docker", + "localdev" + ], + "author": "Mike Pirog", + "license": "MIT", + "dependencies": { + "express": "^4.19.2" + }, + "devDependencies": { + "grunt-contrib-compass": "^1.1.1", + "nodemon": "^3.0.1" + } +} diff --git a/examples/22/src/app-custom.js b/examples/22/src/app-custom.js new file mode 100644 index 0000000..b47fc14 --- /dev/null +++ b/examples/22/src/app-custom.js @@ -0,0 +1,28 @@ +/** + * Lando node express example + * + * @name taylorswift + */ + +'use strict'; + +// Load modules +const fs = require('fs'); +const http = require('http'); +const https = require('https'); +const express = require('express'); +const app = express(); + +// Create our HTTPS server options +const key = fs.readFileSync('/certs/cert.key'); +const cert = fs.readFileSync('/certs/cert.crt'); + +// Create our servers +https.createServer({key, cert}, app).listen(4444); +http.createServer(app).listen(3000); + +// Basic HTTP response +app.get('/', (req, res) => { + res.header('Content-type', 'text/html'); + return res.end('

DANCING DANCING STARLIGHT

'); +}); diff --git a/examples/22/src/app-http.js b/examples/22/src/app-http.js new file mode 100644 index 0000000..fe682e2 --- /dev/null +++ b/examples/22/src/app-http.js @@ -0,0 +1,21 @@ +/** + * Lando node express example + * + * @name taylorswift + */ + +'use strict'; + +// Load modules +const http = require('http'); +const express = require('express'); +const app = express(); + +// Create our server +http.createServer(app).listen(80); + +// Basic HTTP response +app.get('/', (req, res) => { + res.header('Content-type', 'text/html'); + return res.end('

I said "Oh my!" What a marvelous tune!!!

'); +}); diff --git a/examples/22/src/app-https.js b/examples/22/src/app-https.js new file mode 100644 index 0000000..84c81bf --- /dev/null +++ b/examples/22/src/app-https.js @@ -0,0 +1,28 @@ +/** + * Lando node express example + * + * @name taylorswift + */ + +'use strict'; + +// Load modules +const fs = require('fs'); +const http = require('http'); +const https = require('https'); +const express = require('express'); +const app = express(); + +// Create our HTTPS server options +const key = fs.readFileSync('/certs/cert.key'); +const cert = fs.readFileSync('/certs/cert.crt'); + +// Create our servers +https.createServer({key, cert}, app).listen(443); +http.createServer(app).listen(3000); + +// Basic HTTP response +app.get('/', (req, res) => { + res.header('Content-type', 'text/html'); + return res.end('

I said "Oh my!" What a marvelous tune!!!

'); +}); diff --git a/examples/23/.gitignore b/examples/23/.gitignore new file mode 100644 index 0000000..740a0a4 --- /dev/null +++ b/examples/23/.gitignore @@ -0,0 +1,3 @@ +node_modules +*.log +package-lock.json diff --git a/examples/23/.lando.yml b/examples/23/.lando.yml new file mode 100644 index 0000000..bd1edc0 --- /dev/null +++ b/examples/23/.lando.yml @@ -0,0 +1,37 @@ +name: lando-node-23 +services: + defaults: + type: node:23 + build: + - yarn + command: /app/node_modules/.bin/nodemon src/app-http.js --watch src --ignore *.test.js + cli: + type: node + compass: + type: node:23 + globals: + grunt-cli: latest + custom: + type: node:23 + ssl: true + globals: + gulp-cli: latest + port: 3000 + build: + - yarn + command: /app/node_modules/.bin/nodemon src/app-https.js --watch src --ignore *.test.js + custom2: + type: node:23.3.0 + ssl: 4444 + port: 3000 + build: + - yarn + command: /app/node_modules/.bin/nodemon src/app-custom.js --watch src --ignore *.test.js +tooling: + grunt: + service: compass + +# This is important because it lets lando know to test against the plugin in this repo +# DO NOT REMOVE THIS! +plugins: + "@lando/node": ../.. diff --git a/examples/23/README.md b/examples/23/README.md new file mode 100644 index 0000000..e102c06 --- /dev/null +++ b/examples/23/README.md @@ -0,0 +1,83 @@ +# Node 23 Example + +This example exists primarily to test the following documentation: + +* [Node 14-23 Service](https://docs.devwithlando.io/tutorials/node.html) +* [Installing compass in your node service](https://docs.lando.dev/guides/using-compass-on-a-lando-node-service.html) + +## Start up tests + +Run the following commands to get up and running with this example. + +```bash +# Should start up successfully +lando poweroff +lando start +``` + +## Verification commands + +Run the following commands to validate things are rolling as they should. + +```bash +# Should use 23.x as the default version +lando exec defaults -- "env | grep NODE_VERSION=23." + +# Should use a user specified version if given +lando exec custom -- "env | grep NODE_VERSION=23." + +# Should use a user specified patch version if given +lando exec custom2 -- "env | grep NODE_VERSION=23.3.0" + +# Should serve over port 80 by default +lando exec defaults -- "curl http://localhost | grep tune" + +# Should set NODE_EXTRA_CA_CERTS with lando domain CA +lando exec defaults -- "env" | grep NODE_EXTRA_CA_CERTS | grep "$LANDO_CA_CERT" + +# Should only serve over http by default +lando exec defaults -- "curl https://localhost" || echo $? | grep 7 + +# Should serve over specified ports if given +lando exec custom -- "curl http://localhost:3000 | grep tune" + +# Should serve over https is ssl is set by user +lando exec custom -- "curl https://localhost | grep tune" + +# Should servce over a custom https port if ssl is set to a specific port +lando exec custom2 -- "curl https://localhost:4444 | grep DANCING" + +# Should run as root if it needs to +lando exec defaults -- "ps -a -u root" | grep "node" | wc -l | grep 2 +lando exec custom -- "ps -a -u root" | grep "node" | wc -l | grep 2 + +# Should run as node if it can +lando exec custom2 -- "ps -a -u node" | grep "node" | wc -l | grep 2 + +# Should install global dependencies if specified by user and have them available in PATH +lando exec custom -- "gulp -v" +lando exec custom -- "which gulp | grep /var/www/.npm-global" + +# Should PATH prefer node dependency binaries installed in /app/node_modules over global ones +lando exec custom -- "npm install gulp-cli --no-save" +lando exec custom -- "gulp -v" +lando exec custom -- "which gulp | grep /app/node_modules/.bin" +lando exec custom -- "npm uninstall gulp-cli" +lando exec custom -- "which gulp | grep /var/www/.npm-global" + +# Should not serve port for cli +lando exec cli -- "curl http://localhost" || echo $? | grep 7 + +# Should install gruntcli +lando grunt -V +``` + +## Destroy tests + +Run the following commands to trash this app like nothing ever happened. + +```bash +# Should be destroyed with success +lando destroy -y +lando poweroff +``` diff --git a/examples/23/package.json b/examples/23/package.json new file mode 100644 index 0000000..7f9f428 --- /dev/null +++ b/examples/23/package.json @@ -0,0 +1,27 @@ +{ + "name": "node-lando", + "version": "1.0.0", + "description": "Node example for Lando", + "main": "app.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://github.com/lando/lando/tree/master/examples/node" + }, + "keywords": [ + "node", + "docker", + "localdev" + ], + "author": "Mike Pirog", + "license": "MIT", + "dependencies": { + "express": "^4.19.2" + }, + "devDependencies": { + "grunt-contrib-compass": "^1.1.1", + "nodemon": "^3.0.1" + } +} diff --git a/examples/23/src/app-custom.js b/examples/23/src/app-custom.js new file mode 100644 index 0000000..b47fc14 --- /dev/null +++ b/examples/23/src/app-custom.js @@ -0,0 +1,28 @@ +/** + * Lando node express example + * + * @name taylorswift + */ + +'use strict'; + +// Load modules +const fs = require('fs'); +const http = require('http'); +const https = require('https'); +const express = require('express'); +const app = express(); + +// Create our HTTPS server options +const key = fs.readFileSync('/certs/cert.key'); +const cert = fs.readFileSync('/certs/cert.crt'); + +// Create our servers +https.createServer({key, cert}, app).listen(4444); +http.createServer(app).listen(3000); + +// Basic HTTP response +app.get('/', (req, res) => { + res.header('Content-type', 'text/html'); + return res.end('

DANCING DANCING STARLIGHT

'); +}); diff --git a/examples/23/src/app-http.js b/examples/23/src/app-http.js new file mode 100644 index 0000000..fe682e2 --- /dev/null +++ b/examples/23/src/app-http.js @@ -0,0 +1,21 @@ +/** + * Lando node express example + * + * @name taylorswift + */ + +'use strict'; + +// Load modules +const http = require('http'); +const express = require('express'); +const app = express(); + +// Create our server +http.createServer(app).listen(80); + +// Basic HTTP response +app.get('/', (req, res) => { + res.header('Content-type', 'text/html'); + return res.end('

I said "Oh my!" What a marvelous tune!!!

'); +}); diff --git a/examples/23/src/app-https.js b/examples/23/src/app-https.js new file mode 100644 index 0000000..84c81bf --- /dev/null +++ b/examples/23/src/app-https.js @@ -0,0 +1,28 @@ +/** + * Lando node express example + * + * @name taylorswift + */ + +'use strict'; + +// Load modules +const fs = require('fs'); +const http = require('http'); +const https = require('https'); +const express = require('express'); +const app = express(); + +// Create our HTTPS server options +const key = fs.readFileSync('/certs/cert.key'); +const cert = fs.readFileSync('/certs/cert.crt'); + +// Create our servers +https.createServer({key, cert}, app).listen(443); +http.createServer(app).listen(3000); + +// Basic HTTP response +app.get('/', (req, res) => { + res.header('Content-type', 'text/html'); + return res.end('

I said "Oh my!" What a marvelous tune!!!

'); +});