Skip to content

fix: correct checking for runtime version installed in the project and provide example API endpoint in code snippets #230

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

Merged
merged 5 commits into from
Nov 21, 2024
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export async function netlifyCommonEngineHandler(request: Request, context: any)
// Example API endpoints can be defined here.
// Uncomment and define endpoints as necessary.
// const pathname = new URL(request.url).pathname;
// if (pathname = '/api/hello') {
// if (pathname === '/api/hello') {
// return Response.json({ message: 'Hello from the API' });
// }

Expand All @@ -145,7 +145,7 @@ export async function netlifyAppEngineHandler(request: Request): Promise<Respons
// Example API endpoints can be defined here.
// Uncomment and define endpoints as necessary.
// const pathname = new URL(request.url).pathname;
// if (pathname = '/api/hello') {
// if (pathname === '/api/hello') {
// return Response.json({ message: 'Hello from the API' });
// }

Expand Down
7 changes: 5 additions & 2 deletions src/helpers/getPackageVersion.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const { createRequire } = require('node:module')
const { join } = require('node:path/posix')

const { readJSON } = require('fs-extra')

/**
Expand Down Expand Up @@ -29,8 +32,8 @@ module.exports.getAngularVersion = getAngularVersion
const getAngularRuntimeVersion = async function (root) {
let packagePath
try {
// eslint-disable-next-line n/no-missing-require
packagePath = require.resolve('@netlify/angular-runtime/package.json', { paths: [root] })
const siteRequire = createRequire(join(root, ':internal:'))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the previous version ended up not working when actually installed and resulted in MODULE_NOT_FOUND (that was not immediate apparent, because we swallow the error message)

packagePath = siteRequire.resolve('@netlify/angular-runtime/package.json')
} catch {
// module not found
return
Expand Down
16 changes: 15 additions & 1 deletion src/helpers/serverModuleHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ import { render } from '@netlify/angular-runtime/common-engine'
const commonEngine = new CommonEngine()

export async function netlifyCommonEngineHandler(request: Request, context: any): Promise<Response> {
// Example API endpoints can be defined here.
// Uncomment and define endpoints as necessary.
// const pathname = new URL(request.url).pathname;
// if (pathname === '/api/hello') {
// return Response.json({ message: 'Hello from the API' });
// }

return await render(commonEngine)
}
`
Expand All @@ -29,6 +36,13 @@ const angularAppEngine = new AngularAppEngine()
export async function netlifyAppEngineHandler(request: Request): Promise<Response> {
const context = getContext()

// Example API endpoints can be defined here.
// Uncomment and define endpoints as necessary.
// const pathname = new URL(request.url).pathname;
// if (pathname === '/api/hello') {
// return Response.json({ message: 'Hello from the API' });
// }

const result = await angularAppEngine.handle(request, context)
return result || new Response('Not found', { status: 404 })
}
Expand Down Expand Up @@ -113,7 +127,7 @@ const fixServerTs = async function ({ angularVersion, siteRoot, failPlugin, fail
)
} else if (!satisfies(angularRuntimeVersionInstalledByUser, '>=2.2.0', { includePrerelease: true })) {
failBuild(
`Angular@19 SSR on Netlify requires '@netlify/angular-runtime' version 2.2.0 or later to be installed. Found version "${angularRuntimeVersionInstalledByUser}. Please update it to version 2.2.0 or later and try again.`,
`Angular@19 SSR on Netlify requires '@netlify/angular-runtime' version 2.2.0 or later to be installed. Found version "${angularRuntimeVersionInstalledByUser}". Please update it to version 2.2.0 or later and try again.`,
)
}

Expand Down