Skip to content

Commit

Permalink
fix(coherence): update setup command to detect server file (#10060)
Browse files Browse the repository at this point in the history
Similar to #10055, updates the
setup command for Coherence to detect the server file. This deployed
successfully in this commit on deploy target CI here:
redwoodjs/deploy-target-ci@4e5883e.
  • Loading branch information
jtoar committed Feb 27, 2024
1 parent 1bf5e87 commit fe6f555
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

## Unreleased

- fix(coherence): update setup command to detect server file

The `yarn rw setup deploy coherence` command now detects if your project has the server file and configures the api prod command accordingly:

```yml
# coherence.yml

api:
# ...
prod:
command: ["yarn", "rw", "build", "api", "&&", "yarn", "node", "api/dist/server.js", "--apiRootPath=/api"]
```
- Update jsdoc for ScenarioData type (#29166)
Fix formatting of JSDocs in `scenario.ts`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,25 @@ async function getCoherenceConfigFileContent() {
db = 'postgres'
}

return coherenceFiles.yamlTemplate(db)
const hasServerFile = fs.pathExistsSync(
path.join(getPaths().api.dist, 'server.js')
)
const apiProdCommand = ['yarn', 'rw', 'build', 'api', '&&']
if (!hasServerFile) {
apiProdCommand.push(
'yarn',
'node',
'api/dist/server.js',
'--apiRootPath=/api'
)
} else {
apiProdCommand.push('yarn', 'rw', 'serve', 'api', '--apiRootPath=/api')
}

return coherenceFiles.yamlTemplate({
db,
apiProdCommand: `[${apiProdCommand.map((cmd) => `"${cmd}"`).join(', ')}]`,
})
}

const SUPPORTED_DATABASES = ['mysql', 'postgresql']
Expand Down Expand Up @@ -191,13 +209,13 @@ const PORT_REGEXP = /port(\s*)=(\s*)(?<port>\d{4})/g
// ------------------------

const coherenceFiles = {
yamlTemplate(db) {
yamlTemplate({ db, apiProdCommand }) {
return `\
api:
type: backend
url_path: "/api"
prod:
command: ["yarn", "rw", "build", "api", "&&", "yarn", "rw", "serve", "api", "--apiRootPath=/api"]
command: ${apiProdCommand}
dev:
command: ["yarn", "rw", "build", "api", "&&", "yarn", "rw", "dev", "api", "--apiRootPath=/api"]
local_packages: ["node_modules"]
Expand Down

0 comments on commit fe6f555

Please sign in to comment.