playground-tools icon indicating copy to clipboard operation
playground-tools copied to clipboard

Allow express app to be (optionally) passed to start-server

Open Shelob9 opened this issue 8 months ago • 4 comments

What?

  • Add optional app arg to startServer that is express app.

Why?

I wanted to see if I could integrate this with an existing express app. I was able to make it work with one small change that I think is a useful change. Would allow using WordPress for part of a node application and or easily plug this package into existing application

This is what I am thinking:

import {
	getWpNowConfig,
	startServer
} from '@wp-now/wp-now';

const options = await getWpNowConfig({});
const app = express();
app.get('/api', (req, res) => {
	res.json({message:"Hi Roy"})
});
const {  url } = await startServer({...options,app});
console.log({url})

How?

  • Makes it optional arg
  • Uses that app if needed

Testing Instructions

No Changes test

  1. Check out the branch.
  2. npx nx preview wp-now start
  3. Should work as-is, no changes.

Works this way test

  1. Check out the branch.
  2. Link npm link @wp-now/wp-now https://docs.npmjs.com/cli/v9/commands/npm-link
  3. Make a new project
  4. Install this wp-now locally
  5. Test it with above example code

Shelob9 avatar May 31 '24 16:05 Shelob9