feat: correctly subs out ability to boot REST API within same process

This commit is contained in:
Jarrod Flesch
2024-02-01 14:07:13 -05:00
parent e96c7bf987
commit 24feace60b
16 changed files with 2551 additions and 2714 deletions

3
test/REST_API/.env.test Normal file
View File

@@ -0,0 +1,3 @@
PAYLOAD_SECRET=PAYLOAD_CUSTOM_SERVER_EXAMPLE_SECRET_KEY
APP_ENV=test
__NEXT_TEST_MODE=jest

5
test/REST_API/next-env.d.ts vendored Normal file
View File

@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.

View File

@@ -0,0 +1,37 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
outputFileTracingExcludes: {
'**/*': ['drizzle-kit', 'drizzle-kit/utils'],
},
serverComponentsExternalPackages: [
'drizzle-kit',
'drizzle-kit/utils',
'pino',
'pino-pretty',
'mongodb-memory-server',
],
},
reactStrictMode: false,
// transpilePackages: ['@payloadcms/db-mongodb', 'mongoose'],
webpack: (config) => {
if (process.env.PAYLOAD_CONFIG_PATH) {
config.resolve.alias['payload-config'] = process.env.PAYLOAD_CONFIG_PATH
}
return {
...config,
externals: [
...config.externals,
'drizzle-kit',
'drizzle-kit/utils',
'pino',
'pino-pretty',
'mongoose',
'sharp',
],
}
},
}
module.exports = nextConfig

View File

@@ -0,0 +1,26 @@
{
"name": "dev",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@payloadcms/db-mongodb": "workspace:*",
"@payloadcms/next": "workspace:*",
"next": "14.1.1-canary.26",
"payload": "workspace:*",
"react": "18.3.0-canary-247738465-20240130",
"react-dom": "18.3.0-canary-247738465-20240130"
},
"devDependencies": {
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"sass": "^1.69.5",
"typescript": "^5"
}
}

View File

@@ -0,0 +1,4 @@
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
/* DO NOT MODIFY it because it could be re-written at any time. */
export { DELETE, GET, PATCH, POST } from '@payloadcms/next/routes'

View File

@@ -0,0 +1,3 @@
export const GET = async (request: Request) => {
return Response.json({ message: 'Hello world!' })
}

View File

@@ -0,0 +1,32 @@
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"target": "ESNext",
"composite": true, // Make sure typescript knows that this module depends on their references
"allowImportingTsExtensions": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@payloadcms/db-mongodb": ["../../packages/db-mongodb/src"],
"@payloadcms/next/*": ["../../packages/next/src/*"]
}
},
"include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"],
"composite": true, // Make sure typescript knows that this module depends on their references
"references": [{ "path": "../../packages/next" }, { "path": "../../packages/db-mongodb" }]
}