Skip to content

Commit beb1a6a

Browse files
committed
Connectors for version v5.0.3
1 parent 0fc3a8f commit beb1a6a

File tree

452 files changed

+74411
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

452 files changed

+74411
-0
lines changed

edgio-angular-connector/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/stage
2+
!test/app/dist

edgio-angular-connector/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @edgio/angular
2+
3+
Run server-side rendered Angular apps on the [Edgio](https://docs.edg.io).
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'@babel/preset-env',
5+
{
6+
targets: {
7+
node: '14', // NODE_VERSION
8+
},
9+
},
10+
],
11+
],
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// This file was automatically added by edgio init.
2+
// You should commit this file to source control.
3+
// Learn more about this file at https://docs.edg.io/guides/edgio_config
4+
module.exports = {
5+
connector: '@edgio/angular',
6+
7+
// The name of the site in Edgio to which this app should be deployed.
8+
// name: 'my-site-name',
9+
10+
// The name of the team in Edgio to which this app should be deployed.
11+
// team: 'my-team-name',
12+
13+
// backends: {
14+
// origin: {
15+
// // The domain name or IP address of the origin server
16+
// domainOrIp: 'example.com',
17+
//
18+
// // When provided, the following value will be sent as the host header when connecting to the origin.
19+
// // If omitted, the host header from the browser will be forwarded to the origin.
20+
// hostHeader: 'example.com',
21+
//
22+
// // Uncomment the following line if TLS is not set up properly on the origin domain and you want to ignore TLS errors
23+
// // disableCheckCert: true,
24+
//
25+
// // Overrides the default ports (80 for http and 443 for https) and instead use a specific port
26+
// // when connecting to the origin
27+
// // port: 1337,
28+
// },
29+
// },
30+
31+
// Overrides the default path to the routes file. The path should be relative to the root of your app.
32+
// routes: 'routes.js',
33+
34+
// The maximum number of URLs that will be concurrently prerendered during deployment when static prerendering is enabled.
35+
// Defaults to 200, which is the maximum allowed value.
36+
// prerenderConcurrency: 200,
37+
38+
// A list of glob patterns identifying which source files should be uploaded when running edgio deploy --includeSources.
39+
// This option is primarily used to share source code with Edgio support personnel for the purpose of debugging. If omitted,
40+
// edgio deploy --includeSources will result in all files which are not gitignored being uploaded to Edgio.
41+
//
42+
// sources : [
43+
// '**/*', // include all files
44+
// '!(**/secrets/**/*)', // except everything in the secrets directory
45+
// ],
46+
47+
// Allows you to include additional resources in the bundle that is deployed to Edgio’s serverless JS workers.
48+
// Keys are globs, value can be a boolean or string. This is typically used to ensure that resources
49+
// that need to be dynamically required at runtime such as build manifests for server-side rendering
50+
// or other config files are present in the cloud.
51+
//
52+
// includeFiles: {
53+
// 'lang/**/*': true, // Just includes the specified files
54+
// 'content/**/*': 'another/dir/in/edgio/lambda', // Copies the files into specific directory within Edgio build
55+
// },
56+
57+
// Set to true to include all packages listed in the dependencies property of package.json when deploying to Edgio.
58+
// This option generally isn't needed as Edgio automatically includes all modules imported by your code in the bundle that
59+
// is uploaded during deployment
60+
//
61+
// includeNodeModules: true,
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This file was automatically added by edgio deploy.
2+
// You should commit this file to source control.
3+
4+
const { Router } = require('@edgio/core/router')
5+
const { angularRoutes } = require('@edgio/angular')
6+
7+
module.exports = new Router()
8+
// Prevent search engines from indexing permalink URLs
9+
.noIndexPermalink()
10+
.use(angularRoutes)

edgio-angular-connector/package-lock.json

+23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

edgio-angular-connector/package.json

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"name": "@edgio/angular",
3+
"version": "5.0.3",
4+
"license": "Apache-2.0",
5+
"edgio-publish-to-repo": "edgio-docs/edgio-connectors",
6+
"peerDependencies": {
7+
"@edgio/core": "^5.0.0"
8+
},
9+
"devDependencies": {
10+
"@edgio/core": "^5.0.3",
11+
"@types/cross-spawn": "^6.0.2"
12+
},
13+
"scripts": {
14+
"build": "rm -rf ./dist; mkdir ./dist; cp -r package.json README.md default-app ./dist; tsc; cp -r stage/angular/src/* dist;",
15+
"watch": "npm-watch",
16+
"push-build": "npm run build && cd dist && yalc push && cd ..",
17+
"release": "npm run build; cd ./dist; npm publish --access public",
18+
"release:next": "npm run release -- --tag next",
19+
"test": "jest"
20+
},
21+
"watch": {
22+
"push-build": {
23+
"patterns": [
24+
"src",
25+
"package.json",
26+
"default-app"
27+
],
28+
"extensions": "*",
29+
"quiet": false
30+
}
31+
},
32+
"jest": {
33+
"clearMocks": true,
34+
"collectCoverage": true,
35+
"transform": {
36+
"^.+\\.(js)?$": "babel-jest",
37+
"^.+\\.ts$": "ts-jest"
38+
},
39+
"moduleFileExtensions": [
40+
"ts",
41+
"js",
42+
"json"
43+
],
44+
"transformIgnorePatterns": [
45+
"<rootDir>/node_modules/"
46+
],
47+
"collectCoverageFrom": [
48+
"./src/router/**/*.ts",
49+
"!**/index.ts"
50+
],
51+
"moduleNameMapper": {
52+
"^@edgio/core(.*)$": "<rootDir>/../core/dist/$1",
53+
"^@edgio/angular(.*)$": "<rootDir>/../angular/src/$1"
54+
}
55+
},
56+
"publishConfig": {
57+
"directory": "dist"
58+
}
59+
}

edgio-angular-connector/src/build.ts

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { getOutputPath } from './utils/getBuildPath'
2+
import { read as readPackageJson } from '@edgio/core/utils/packageUtils'
3+
import FrameworkBuildError from '@edgio/core/errors/FrameworkBuildError'
4+
import { join } from 'path'
5+
import { DeploymentBuilder, BuildOptions } from '@edgio/core/deploy'
6+
7+
const appDir = process.cwd()
8+
const distDir = join(appDir, 'dist')
9+
const builder = new DeploymentBuilder(appDir)
10+
11+
export default async function build({ skipFramework }: BuildOptions) {
12+
builder.clearPreviousBuildOutput()
13+
14+
const pkg = readPackageJson()
15+
const isSsr = pkg.scripts['build:ssr']
16+
17+
if (!skipFramework) {
18+
const command = `npm run build${isSsr ? ':ssr' : ''}`
19+
20+
// clear dist directory
21+
builder.emptyDirSync(distDir)
22+
23+
try {
24+
// run the build command
25+
await builder.exec(command)
26+
} catch (e) {
27+
throw new FrameworkBuildError('Angular', command, e)
28+
}
29+
}
30+
31+
const assetsPath = getOutputPath('build')
32+
const serverPath = getOutputPath('server')
33+
34+
// if this is an SSR build, add the server to the bundle
35+
if (serverPath) {
36+
// Include the angular server which is loaded by the prod entrypoint
37+
builder.addJSAsset(
38+
join(appDir, serverPath, 'main.js'),
39+
join('__backends__', 'angular-server.js')
40+
)
41+
}
42+
43+
builder
44+
// angular.json
45+
.addJSAsset(join(appDir, 'angular.json'), 'angular.json')
46+
// browser assets
47+
.addStaticAsset(join(appDir, assetsPath), '/')
48+
// Index html required by Universal engine
49+
.addJSAsset(join(appDir, assetsPath, 'index.html'), join('/', assetsPath, 'index.html'))
50+
51+
// exclude the prod handler if we're building only static (no SSR)
52+
await builder.build({ excludeProdEntryPoint: !serverPath })
53+
}

edgio-angular-connector/src/dev.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* istanbul ignore file */
2+
import createDevServer from '@edgio/core/dev/createDevServer'
3+
4+
export default async function dev() {
5+
return createDevServer({
6+
label: 'Angular',
7+
command: port => `npx ng serve --port ${port}`,
8+
ready: [/compiled successfully/i],
9+
filterOutput: line => {
10+
return line.match(/\w/) && !line.match(/listening on/i) ? true : false
11+
},
12+
})
13+
}

edgio-angular-connector/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './router'

edgio-angular-connector/src/init.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { join } from 'path'
2+
import { DeploymentBuilder } from '@edgio/core/deploy'
3+
4+
/**
5+
* Adds all required dependencies and files to the user's app by copying them
6+
* over from src/default-app.
7+
*/
8+
module.exports = function init() {
9+
new DeploymentBuilder(process.cwd())
10+
.addDefaultAppResources(join(__dirname, 'default-app'))
11+
.addDefaultEdgioScripts()
12+
}

edgio-angular-connector/src/prod.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* istanbul ignore file */
2+
export default async function prod(port: number) {
3+
return new Promise((resolve, reject) => {
4+
try {
5+
require('./angular-server').app().listen(port, resolve)
6+
} catch (e) {
7+
reject(e)
8+
}
9+
})
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { BACKENDS } from '@edgio/core/constants'
2+
import PluginBase from '@edgio/core/plugins/PluginBase'
3+
import { Router } from '@edgio/core/router'
4+
import { getBuildPath, getOutputPath } from '../utils/getBuildPath'
5+
6+
/**
7+
* A TTL for assets that never change. 10 years in seconds.
8+
*/
9+
const FAR_FUTURE_TTL = 60 * 60 * 24 * 365 * 10
10+
11+
const PUBLIC_CACHE_CONFIG = {
12+
edge: {
13+
maxAgeSeconds: FAR_FUTURE_TTL,
14+
},
15+
}
16+
17+
export default class AngularRoutes extends PluginBase {
18+
angularRouteGroupName = 'angular_routes_group'
19+
20+
/**
21+
* Called when plugin is registered
22+
* @private
23+
* @param router
24+
*/
25+
onRegister(router: Router) {
26+
const buildPath = getBuildPath()
27+
28+
router.group(this.angularRouteGroupName, group => {
29+
group.match('/service-worker.js', ({ serviceWorker }) => {
30+
serviceWorker(`dist/__edgio__/service-worker.js`)
31+
})
32+
group.match('/assets/:path*', ({ cache, serveStatic }) => {
33+
cache(PUBLIC_CACHE_CONFIG)
34+
serveStatic(`${buildPath}/assets/:path`)
35+
})
36+
group.static(buildPath, {
37+
handler: () => res => res.cache(PUBLIC_CACHE_CONFIG),
38+
glob: `*`,
39+
})
40+
41+
// we can determine SSR support by whether or not a server output path exists
42+
const isSsr = !!getOutputPath('server')
43+
44+
if (isSsr) {
45+
group.match('/:path*', async ({ proxy }) => {
46+
proxy(BACKENDS.js)
47+
})
48+
} else {
49+
group.match(
50+
'/:path*',
51+
async ({ serveStatic }) =>
52+
await serveStatic(`${buildPath}/:path*`, {
53+
onNotFound: async () => await serveStatic(`${buildPath}/index.html`),
54+
})
55+
)
56+
}
57+
})
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import AngularRoutes from './AngularRoutes'
2+
3+
export const angularRoutes = new AngularRoutes()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { join } from 'path'
2+
import nonWebpackRequire from '@edgio/core/utils/nonWebpackRequire'
3+
4+
/**
5+
* Gets the contents of angular.json as an object
6+
*/
7+
export function getAngularConfig() {
8+
const angularConfigPath = join(process.cwd(), 'angular.json')
9+
return nonWebpackRequire(angularConfigPath)
10+
}
11+
12+
/**
13+
* Returns the config for the defaultProject in angularConfig.json,
14+
* or the config for env.ANGULAR_PROJECT if defined
15+
*/
16+
export function getAngularProject() {
17+
const angularConfig = getAngularConfig()
18+
return process.env.ANGULAR_PROJECT || angularConfig.defaultProject
19+
}
20+
21+
/**
22+
* Gets the outputPath prop from angular.json for the given project and type under
23+
* /projects/<angular-project>/architect/<type>/options
24+
*/
25+
export function getOutputPath(type: 'build' | 'server') {
26+
const angularConfig = getAngularConfig()
27+
const angularProject = getAngularProject()
28+
29+
return angularConfig.projects[angularProject].architect[type]?.options?.outputPath
30+
}
31+
32+
export const getBuildPath = () => getOutputPath('build')

0 commit comments

Comments
 (0)