Skip to content

Commit

Permalink
fix(edgio): support v7 edgio application
Browse files Browse the repository at this point in the history
  • Loading branch information
DemoMacro committed Jan 10, 2024
1 parent 50cd917 commit 7b93d69
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 31 deletions.
9 changes: 5 additions & 4 deletions docs/content/2.deploy/20.providers/edgio.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,25 @@ You can use Nitropack to test your app's developement experience locally:
NITRO_PRESET=edgio npx nitropack build
```

To simulate on local how your app would run in production with Edgio, run the following command:
To simulate on local how your app would run in production with Edgio, locate the output directory and run the following command:

```bash
edgio build && edgio run --production
# cd `.output` dir and install dependencies before then
npm run preview
```

## Deploying from your local machine

Once you have tested your application locally, you may deploy using:

```bash
edgio deploy
npm run deploy
```

## Deploying using CI/CD

If you are deploying from a non-interactive environment, you will need to create an account on [Edgio Developer Console](https://app.layer0.co) first and setup a [deploy token](https://docs.edg.io/guides/basics/deployments#deploy-from-ci). Once the deploy token is created, save it as a secret to your environment. You can start the deploy by running:

```bash
edgio deploy --token=XXX
npm run deploy --token=XXX
```
37 changes: 10 additions & 27 deletions src/presets/edgio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@ export const edgio = defineNitroPreset({
resolve(nitro.options.output.dir, "edgio.config.js"),
`module.exports = ${JSON.stringify(
{
connector: "./edgio",
connector: "@edgio/nitropack",
routes: "./routes.js",
backends: {},
includeFiles: {
"server/**": true,
},
},
null,
2
Expand All @@ -43,34 +39,20 @@ export const edgio = defineNitroPreset({
await writeFile(
resolve(nitro.options.output.dir, "routes.js"),
`
import { Router } from '@edgio/core/router'
import { isProductionBuild } from '@edgio/core/environment'
import { isProductionBuild } from "@edgio/core/environment";
import { Router } from "@edgio/core/router";
import { nitropackRoutes } from "@edgio/nitropack";
const router = new Router()
const router = new Router().use(nitropackRoutes);
if (isProductionBuild()) {
router.static('public')
router.static("public");
}
router.fallback(({ renderWithApp }) => { renderWithApp() })
export default router
export default router;
`.trim()
);

// Write edgio/prod.js
await writeFile(
resolve(nitro.options.output.dir, "edgio/prod.js"),
`
module.exports = async function entry (port) {
process.env.PORT = process.env.NITRO_PORT = port.toString()
console.log('Starting Edgio server on port', port)
await import('../server/index.mjs')
console.log('Edgio server started')
}
`.trim()
);

// Write and prepare package.json for deployment
await writeFile(
resolve(nitro.options.output.dir, "package.json"),
Expand All @@ -86,8 +68,9 @@ module.exports = async function entry (port) {
preview: "npm i && edgio build && edgio run --production",
},
devDependencies: {
"@edgio/cli": "^6",
"@edgio/core": "^6",
"@edgio/cli": "^7",
"@edgio/core": "^7",
"@edgio/nitropack": "^7",
},
},
null,
Expand Down

0 comments on commit 7b93d69

Please sign in to comment.