Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
14 changes: 14 additions & 0 deletions 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