Skip to content

Commit

Permalink
add layer0 config
Browse files Browse the repository at this point in the history
  • Loading branch information
jillesmc committed May 20, 2021
1 parent 91aac36 commit 5b609a2
Show file tree
Hide file tree
Showing 10 changed files with 2,954 additions and 89 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ yarn-error.log*

# vercel
.vercel
# Layer0 generated build directory
.layer0
17 changes: 17 additions & 0 deletions layer0.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// This file was automatically added by layer0 deploy.
// You should commit this file to source control.
require('dotenv-flow').config();

module.exports = {
routes: './routes.ts',
connector: '@layer0/next',
backends: {
origin: {
domainOrIp: process.env.LEGACY_BACKEND_DOMAIN || 'legacy.example.com.br',
hostHeader: process.env.LEGACY_BACKEND_HOST_HEADER || 'legacy.example.com.br',
},
},
includeFiles: {
'_content_cache/**/*': true,
},
};
25 changes: 12 additions & 13 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
/* eslint-disable no-param-reassign */

const { withLayer0, withServiceWorker } = require('@layer0/next/config')
// const withPlugins = require('next-compose-plugins')
const { withSentryConfig } = require('@sentry/nextjs');
const { withSentryConfig } = require('@sentry/nextjs')
const withSourceMaps = require('@zeit/next-source-maps')({
devtool: 'hidden-source-map',
})

const {
NEXT_PUBLIC_SENTRY_DSN: SENTRY_DSN,
NEXT_PUBLIC_APP_STAGE,
VERCEL_GITHUB_COMMIT_SHA,
} = process.env

// The Sentry WebpackPlugin is used to upload sourcemaps at buildtime and
// it looks for an environment variable specifically SENTRY_DSN,
// so we need to map it so it works properly.
// See:
// https://github.com/getsentry/sentry-webpack-plugin
// https://docs.sentry.io/cli/configuration
process.env.SENTRY_DSN = SENTRY_DSN

const basePath = ''
const nextConfig = {
future: {
Expand All @@ -30,7 +21,6 @@ const nextConfig = {
},
publicRuntimeConfig: {
// Will be available on both server and client
SENTRY_DSN,
NEXT_PUBLIC_APP_STAGE,
},
env: {
Expand Down Expand Up @@ -66,6 +56,15 @@ const nextConfig = {
}
const SentryWebpackPluginOptions = {}

module.exports = withSentryConfig(withSourceMaps({ ...nextConfig }), SentryWebpackPluginOptions)
module.exports = withSentryConfig(
withLayer0(
withServiceWorker(
withSourceMaps({
...nextConfig,
})
)
),
SentryWebpackPluginOptions
)

// module.exports = withPlugins([[withSourceMaps]], nextConfig)
18 changes: 14 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"name": "atlas",
"author": "Jilles Cardoso <[email protected]> (https://github.com/jillesmc)",
"license": "MIT",
"version": "1.0.0",
"scripts": {
"layer0:dev": "layer0 dev",
"layer0:build": "layer0 build",
"layer0:deploy": "layer0 deploy",
"dev": "NODE_OPTIONS='--inspect' next dev",
"build": "yarn test-all && next build",
"start": "next start",
Expand All @@ -15,6 +14,10 @@
"clean": "npx del-cli .next/",
"analyze": "yarn clean && cross-env ANALYZE=true yarn build"
},
"name": "atlas",
"author": "Jilles Cardoso <[email protected]> (https://github.com/jillesmc)",
"license": "MIT",
"version": "1.0.0",
"husky": {
"hooks": {
"pre-commit": "lint-staged",
Expand Down Expand Up @@ -94,6 +97,12 @@
"winston": "^3.3.3"
},
"devDependencies": {
"@layer0/cli": "^3.8.1",
"@layer0/core": "^3.8.1",
"@layer0/devtools": "^3.8.1",
"@layer0/next": "^3.8.1",
"@layer0/prefetch": "^3.8.1",
"@layer0/react": "^3.8.1",
"@next/bundle-analyzer": "^10.1.2",
"@testing-library/react": "^10.0.1",
"@types/algoliasearch": "^3.34.10",
Expand All @@ -112,6 +121,7 @@
"@welldone-software/why-did-you-render": "^4.3.2",
"babel-jest": "^25.2.3",
"cross-env": "^7.0.2",
"dotenv-flow": "^3.2.0",
"eslint": "^7.2.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^6.10.1",
Expand Down
11 changes: 11 additions & 0 deletions routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This file was automatically added by layer0 deploy.
// You should commit this file to source control.
import { Router } from '@layer0/core/router'
import { nextRoutes } from '@layer0/next'

export default new Router()
.match('/service-worker.js', ({ serviceWorker }) =>
serviceWorker('.next/static/service-worker.js')
)
.use(nextRoutes) // automatically adds routes for all files under /pages
.fallback(({ proxy }) => proxy('origin'))
2 changes: 1 addition & 1 deletion sentry.client.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const SENTRY_DSN = process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN;
Sentry.init({
enabled: !['development'].includes(process.env.NEXT_PUBLIC_APP_STAGE),
environment: process.env.NEXT_PUBLIC_APP_STAGE,
dsn: SENTRY_DSN || 'https://[email protected]/5373761',
dsn: SENTRY_DSN,
// Note: if you want to override the automatic release value, do not set a
// `release` value here - use the environment variable `SENTRY_RELEASE`, so
// that it will also get attached to your source maps
Expand Down
5 changes: 0 additions & 5 deletions sentry.properties

This file was deleted.

2 changes: 1 addition & 1 deletion sentry.server.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const SENTRY_DSN = process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN;
Sentry.init({
enabled: !['development'].includes(process.env.NEXT_PUBLIC_APP_STAGE),
environment: process.env.NEXT_PUBLIC_APP_STAGE,
dsn: SENTRY_DSN || 'https://[email protected]/5373761',
dsn: SENTRY_DSN,
// Note: if you want to override the automatic release value, do not set a
// `release` value here - use the environment variable `SENTRY_RELEASE`, so
// that it will also get attached to your source maps
Expand Down
10 changes: 10 additions & 0 deletions sw/service-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { skipWaiting, clientsClaim } from 'workbox-core';
import { precacheAndRoute } from 'workbox-precaching';
import { Prefetcher } from '@layer0/prefetch/sw';

skipWaiting();
clientsClaim();
// eslint-disable-next-line
precacheAndRoute(self.__WB_MANIFEST || []);

new Prefetcher().route();
Loading

0 comments on commit 5b609a2

Please sign in to comment.