Heroku
Deploy Nitro apps to Heroku.
Preset: heroku
Using the heroku CLI
Create a new Heroku app.heroku create myapp
heroku create myapp
Configure Heroku to use the nodejs buildpack.heroku buildpacks:set heroku/nodejs
heroku buildpacks:set heroku/nodejs
Configure your app.heroku config:set NITRO_PRESET=heroku
heroku config:set NITRO_PRESET=heroku
Ensure you have start
and build
commands in your package.json
file."scripts": {
"build": "nitro build", // or `nuxt build` if using nuxt
"start": "node .output/server/index.mjs"
}
"scripts": {
"build": "nitro build", // or `nuxt build` if using nuxt
"start": "node .output/server/index.mjs"
}
With nginx
Add the heroku Nginx buildpack here
Change to the 'node' preset in your nuxt.config
"nitro": {
"preset":"node",
}
"nitro": {
"preset":"node",
}
From the Existing app section of buildpack doc, 2 key steps are required to get things running
Step 1: Listen on a socket at 'tmp/nginx.socket'
Step 2: Create a file '/tmp/app-initialized' when your app is ready to accept connections
Create custom app runner, eg: apprunner.mjs at the root of the project (or any other preferred location), in this file, create a server, using the listener generated by the node preset, then listen on the socket as detailed in the buildpack docimport { createServer } from 'node:http'
import { listener } from './.output/server/index.mjs'
const server = createServer(listener)
server.listen('/tmp/nginx.socket') //following the buildpack doc
import { createServer } from 'node:http'
import { listener } from './.output/server/index.mjs'
const server = createServer(listener)
server.listen('/tmp/nginx.socket') //following the buildpack doc
To create the 'tmp/app-initialized' file, use a nitro plugin, create file 'initServer.ts' at the root of the project (or any other preferred location)import fs from "fs"
export default defineNitroPlugin((nitroApp) => {
if((process.env.NODE_ENV || 'development') != 'development') {
fs.openSync('/tmp/app-initialized', 'w')
}
})
import fs from "fs"
export default defineNitroPlugin((nitroApp) => {
if((process.env.NODE_ENV || 'development') != 'development') {
fs.openSync('/tmp/app-initialized', 'w')
}
})