Skip to content
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

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

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

Shelob9
Copy link

@Shelob9 Shelob9 commented May 31, 2024

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

@bgrgicak
Copy link
Collaborator

bgrgicak commented Jun 2, 2024

Hey @Shelob9, thanks for working on this. While this could work there is a much better way to do it with Playground instead of WP-NOW.
Playground has a CLI server and it would be great if there was an Express middleware that could run Playground CLI requests.
Would you be up for working on this in the Playground repository?

FYI @juanmaguitar

@Shelob9
Copy link
Author

Shelob9 commented Jun 3, 2024

While this could work there is a much better way to do it with Playground instead of WP-NOW.

Why is this better? The reason I chose to do it this way was:

  • This allows declaring routes before the / route is added by wp-now
  • The function I editted is exported.

@bgrgicak
Copy link
Collaborator

bgrgicak commented Jun 5, 2024

Why is this better?

WP-now is a tool that uses Playground and is built for local development.
Playground CLI is the standard way of running Playground servers. By contributing to the Playground CLI everyone gets the benefits.

@adamziel
Copy link
Collaborator

adamziel commented Jun 5, 2024

A middleware could be used in any express server, while hooking into wp-now makes it specific to the way wp-now is booted and configured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants