Skip to content

Commit

Permalink
feat: build with webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanguy Antoine committed Apr 9, 2020
1 parent d3a437f commit b365327
Show file tree
Hide file tree
Showing 22 changed files with 275 additions and 664 deletions.
3 changes: 0 additions & 3 deletions .dockerignore

This file was deleted.

5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ jspm_packages
.webpack
.env

# Serverless directories
.serverless

.envrc

coverage/
.DS_Store
dist/
yarn-error.log
yarn-error.log
14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"dev": "nodemon ./src/server.ts",
"generate:views": "webpack --config webpack.views.config.js",
"build:old": "yarn generate:views && webpack --config webpack.config.js",
"build": "rimraf dist/ && tsc -p tsconfig.build.json"
"build": "rimraf dist/ && yarn webpack",
"build:views": "rimraf dist/views && yarn webpack --config webpack.views.config.js"
},
"author": "[email protected]",
"license": "ISC",
Expand All @@ -25,6 +26,7 @@
"cookie-parser": "^1.4.3",
"crypto-js": "^3.1.9-1",
"dateformat": "^3.0.3",
"ejs": "^3.0.2",
"express": "^4.16.3",
"express-session": "^1.15.6",
"js-cookie": "^2.2.0",
Expand All @@ -35,17 +37,12 @@
"lodash.pick": "^4.4.0",
"merge": "^1.2.1",
"morgan": "^1.9.1",
"mustache-express": "^1.2.7",
"oauth": "^0.9.15",
"passport": "^0.4.0",
"passport-oauth1": "^1.1.0",
"post-robot": "^8.0.26",
"pug": "^2.0.3",
"simple-oauth2": "^3.0.0",
"sleep": "^6.0.0",
"source-map-support": "^0.5.12",
"vhost": "^3.0.2",
"winston": "^3.2.1"
"vhost": "^3.0.2"
},
"devDependencies": {
"@bearer/tslint-config": "^0.83.5",
Expand All @@ -66,7 +63,6 @@
"@types/nock": "^9.3.0",
"@types/node": "^10.3.6",
"@types/passport-oauth2": "^1.4.5",
"@types/pug": "^2.0.4",
"@types/simple-oauth2": "^2.2.1",
"@types/supertest": "^2.0.5",
"@types/uuid": "^3.4.3",
Expand All @@ -76,6 +72,8 @@
"copy-webpack-plugin": "^5.0.2",
"cz-conventional-changelog": "^2.1.0",
"file-loader": "^3.0.1",
"html-loader": "^1.1.0",
"html-webpack-inline-source-plugin": "^0.0.10",
"html-webpack-plugin": "^3.2.0",
"husky": "^1.3.0",
"jest": "^23.6.0",
Expand Down
5 changes: 1 addition & 4 deletions src/auth/v3/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Request } from 'express'
import { IWithStageVariables } from '../../types'
import Integration from '../../functions/integration'

export interface IAuthContext {
Expand Down Expand Up @@ -95,7 +94,6 @@ interface IAuthConfigSessionData {

export type TConnectConfigRequest = Request &
IAuthContext &
IWithStageVariables &
IAuthConfig &
IAuthConfigSessionData & {
query: {
Expand Down Expand Up @@ -147,12 +145,11 @@ export type TAuthenticateRequest = Request & IAuthContext & IAuthConfig & IWithA
export type TLocalAuthSuccessRequest = Request & IAuthContext & IAuthConfig & IWithAuthCredentials

export type AuthSuccessRequest = Request &
IWithStageVariables &
IAuthContext &
IAuthId &
IWithAuthCredentials & { aliasBuid: string; integrationConfig?: TIntegrationConfig }

export type TRevokeRequest = Request & IWithStageVariables & { buid: string }
export type TRevokeRequest = Request & { buid: string }

export type TErrorHandlerRequest = Request & Partial<IAuthContext> & Partial<IAuthId>

Expand Down
12 changes: 4 additions & 8 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import 'source-map-support/register'
import mustacheExpress from 'mustache-express'
import vhost from 'vhost'

import express from 'express'

import App from './app'
import functions from './functions/router' // proxyFunction

import errorHandler from './errorHandler'
import 'ejs'

import authV3, { authHostRouter } from './auth/v3/router'
import { AUTH_VHOST, PROXY_VHOST } from './constants'
Expand All @@ -24,9 +20,9 @@ const app = App(baseApp)

// console.log(express.static(`${__dirname}./views`))
// const viewsDir = path.join(__dirname, './views')
const viewsDir = process.env.NODE_ENV !== 'production' ? '.webpack/src/views' : './views'
app.engine('mustache', mustacheExpress())
app.set('view engine', 'mustache')
const viewsDir = process.env.NODE_ENV !== 'production' ? './dist/views' : './views'

// app.set('view engine', 'ejs')
app.set('views', viewsDir)

console.log('Auth VHost:', AUTH_VHOST)
Expand Down
5 changes: 2 additions & 3 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AuthDetails } from './auth/v3/types'

export type Omit<T, K> = Pick<T, Exclude<keyof T, K>>

export interface IntegrationServiceRequest extends Request, IWithStageVariables {
export interface IntegrationServiceRequest extends Request {
environmentIdentifier: string
organizationIdentifier: string
}
Expand All @@ -17,8 +17,7 @@ export type TRequest = Request & {
organizationIdentifier?: any
environmentIdentifier?: any
bearerOverhead?: number
} & TWithInstrument &
IWithStageVariables
} & TWithInstrument

export type TServerResponse = {
data: {
Expand Down
11 changes: 0 additions & 11 deletions src/views/callback.mustache

This file was deleted.

14 changes: 14 additions & 0 deletions tsconfig.views.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true,
"allowSyntheticDefaultImports": true,
"downlevelIteration": true,
"esModuleInterop": true,
"lib": ["es5", "es6", "dom", "es2015", "es2015.symbol", "esnext.asynciterable", "es2017", "dom"],
"noUnusedLocals": true,
"strictNullChecks": true,
"skipLibCheck": true
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
</div>
</div>
<div>
<h3>Cannot {{method}} {{callbackUrl}}</h3>
<h3>Cannot <%= method %> <%= callbackUrl %></h3>
<h1>That's Bearer's callback URL</h1>

<p>Register this URL to let Bearer handle your application's OAuth dance.</p>
Expand Down
11 changes: 11 additions & 0 deletions views/callback.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<html>
<head>
<script type="application/javascript">
window.scenarioId = '<%= integrationUuid %>'
window.authId = '<%= authId %>'
window.authError = '<%= error %>'
window.authErrorDescription = '<%= error_description %>'
</script>
</head>
<body></body>
</html>
File renamed without changes.
37 changes: 17 additions & 20 deletions src/views/iframe-script.ts → views/iframe-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,21 @@ postRobot.on(
)

// Revoke user access (remove local storage key for the moment)
postRobot.on(
d.Events.REVOKE,
(event: d.TLogoutPayload): void => {
const { clientId, scenarioId, authId } = event.data
Storage.revoke(scenarioId, clientId)
fetch(`/v2/auth/${scenarioId}/revoke/${authId}?clientId=${clientId}`, {
method: 'DELETE'
})
.then(response => {
// 200 request
if (response.ok) {
postRobot.send(window.parent, d.Events.REVOKE_SUCCEEDED, event.data)
} else {
postRobot.send(window.parent, d.Events.REVOKE_FAILED, event.data)
}
})
.catch(() => {
postRobot.on(d.Events.REVOKE, (event: d.TLogoutPayload): void => {
const { clientId, scenarioId, authId } = event.data
Storage.revoke(scenarioId, clientId)
fetch(`/v2/auth/${scenarioId}/revoke/${authId}?clientId=${clientId}`, {
method: 'DELETE'
})
.then(response => {
// 200 request
if (response.ok) {
postRobot.send(window.parent, d.Events.REVOKE_SUCCEEDED, event.data)
} else {
postRobot.send(window.parent, d.Events.REVOKE_FAILED, event.data)
})
}
)
}
})
.catch(() => {
postRobot.send(window.parent, d.Events.REVOKE_FAILED, event.data)
})
})
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@
</div>
</div>
<div>
<h3>Cannot {{method}} {{callbackUrl}}</h3>
<h3>Cannot <%= method %> <%= callbackUrl %></h3>
<h1>Page Not Found</h1>

<p>The requested URL {{callbackUrl}} could not be found on this server.</p>
<p>The requested URL <%= callbackUrl %> could not be found on this server.</p>
<p>Make sure that you've entered the right URL and try again</p>
<a class="button" href="https://docs.bearer.sh/help-and-support">
<div class="icon-bg">
Expand Down
32 changes: 8 additions & 24 deletions src/views/storage.test.ts → views/storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,10 @@ describe('Storage', () => {
describe('known user', () => {
it('not authorized then authorized', () => {
// Only the correct one is authorized
expect(Storage.hasAuthorized(scenarioTarget, integrationTarget)).toBe(
true
)
expect(Storage.hasAuthorized(scenarioTarget, otherIntegration)).toBe(
false
)
expect(Storage.hasAuthorized(otherScenario, integrationTarget)).toBe(
false
)
expect(Storage.hasAuthorized(otherScenario, otherIntegration)).toBe(
false
)
expect(Storage.hasAuthorized(scenarioTarget, integrationTarget)).toBe(true)
expect(Storage.hasAuthorized(scenarioTarget, otherIntegration)).toBe(false)
expect(Storage.hasAuthorized(otherScenario, integrationTarget)).toBe(false)
expect(Storage.hasAuthorized(otherScenario, otherIntegration)).toBe(false)
})
})

Expand All @@ -94,18 +86,10 @@ describe('Storage', () => {
it('alaways return false', () => {
document.cookie = 'uuid=unknow'

expect(Storage.hasAuthorized(scenarioTarget, integrationTarget)).toBe(
false
)
expect(Storage.hasAuthorized(scenarioTarget, otherIntegration)).toBe(
false
)
expect(Storage.hasAuthorized(otherScenario, integrationTarget)).toBe(
false
)
expect(Storage.hasAuthorized(otherScenario, otherIntegration)).toBe(
false
)
expect(Storage.hasAuthorized(scenarioTarget, integrationTarget)).toBe(false)
expect(Storage.hasAuthorized(scenarioTarget, otherIntegration)).toBe(false)
expect(Storage.hasAuthorized(otherScenario, integrationTarget)).toBe(false)
expect(Storage.hasAuthorized(otherScenario, otherIntegration)).toBe(false)
})
})
})
Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 6 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path')

module.exports = {
entry: { 'src/server': './src/server.ts' },
entry: { 'server/index': './src/server.ts' },
target: 'node',
mode: 'production',
optimization: {
Expand All @@ -18,7 +18,7 @@ module.exports = {
devtool: 'nosources-source-map',
output: {
libraryTarget: 'commonjs2',
path: path.join(__dirname, '.webpack'),
path: path.join(__dirname, 'dist'),
filename: '[name].js',
sourceMapFilename: '[file].map'
},
Expand All @@ -28,7 +28,10 @@ module.exports = {
test: /\.ts(x?)$/,
use: [
{
loader: 'ts-loader'
loader: 'ts-loader',
options: {
configFile: 'tsconfig.build.json'
}
}
],
exclude: /node_modules/
Expand Down
Loading

0 comments on commit b365327

Please sign in to comment.