Skip to content

Commit

Permalink
bump
Browse files Browse the repository at this point in the history
  • Loading branch information
morriq committed Sep 22, 2018
1 parent 74938f4 commit a7f8dbc
Show file tree
Hide file tree
Showing 69 changed files with 347 additions and 480 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ Tailor also injects a RequireJS bundle to your template so you're able to use We

## Fragments

Fragments are small applications.
Fragments are small applications.

They might be React applications, or any other implementation.

Fragments do not need to necessarily render something.
Fragments do not need to necessarily render something.

This app consists basically in a couple of fragments:

- fragment-common
- fragment-header
- fragment-applications-react
- fragment-react
- fragment-chat

Each fragment contains it's own `webpack.config.js` that specifies how to build it.
Expand Down
12 changes: 10 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,22 @@ services:
depends_on:
- jaeger

fragment-simple-vue-test:
build: packages/fragment-simple-vue-test
fragment-vue-client:
build: packages/fragment-vue-client
#restart: always

fragment-vue-file-read:
build: packages/fragment-vue-file-read
#restart: always

fragment-vue-http:
build: packages/fragment-vue-http
#restart: always

fragment-react:
build: packages/fragment-react
#restart: always

fragment-dotnet:
build: packages/fragment-dotnet
ports:
Expand Down
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ const logger = bunyan.createLogger({
const z = new Map();
const tailor = new Tailor({
templatesPath: __dirname + '/templates',
requestFragment(url, attributes, request, span = null) {
const src = z.get(attributes.id);
return tailorFragment(filterReqHeadersFn)(src, attributes, request, span)
},
// requestFragment(url, attributes, request, span = null) {
// const src = z.get(attributes.id);
// return tailorFragment(filterReqHeadersFn)(src, attributes, request, span)
// },
tracer: initTracer(
config,
{
Expand All @@ -50,7 +50,7 @@ module.exports = async (request, response) => {
Object.values(services)
.forEach((a) => {
console.log(a);
z.set(a.Service, 'http://' + a.ServiceAddress + ':' + a.ServicePort)
z.set(a.Service, 'http://' + a.Address + ':' + a.Port)
})

if (request.url === '/favicon.ico') {
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mosaic-tailor-react-example",
"name": "frontend-microservices",
"version": "1.0.0",
"description": "mosaic-tailor-react-example",
"description": "Frontend microservices",
"main": "index.js",
"scripts": {
"start": "micro -l tcp://0.0.0.0:80",
Expand All @@ -12,14 +12,14 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/tsnolan23/mosaic-tailor-react-example.git"
"url": "git+https://github.com/morriq/Frontend-microservices.git"
},
"author": "",
"author": "morriq<[email protected]>",
"license": "ISC",
"bugs": {
"url": "https://github.com/tsnolan23/mosaic-tailor-react-example/issues"
"url": "https://github.com/morriq/Frontend-microservices/issues"
},
"homepage": "https://github.com/tsnolan23/mosaic-tailor-react-example#readme",
"homepage": "https://github.com/morriq/Frontend-microservices#readme",
"devDependencies": {
"babel-eslint": "^9.0.0",
"eslint": "^5.6.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/fragment-common/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const setAddress = (address) => ({ address })
const setPort = port => ({ port })

const getUrlFromPort = (port) => (path) => {
return `//test.local:${port}/${path}`
// @todo
return `//localhost:${port}/${path}`
}

const { env } = process
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
28 changes: 28 additions & 0 deletions packages/fragment-react/environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { machineIdSync } = require('node-machine-id')
const { address } = require('ip')


const setId = (id) => ({ id })
const setName = (name) => ({ name })
const setAddress = (address) => ({ address })
const setPort = port => ({ port })

const getUrlFromPort = (port) => (path) => {
// @todo
return `//localhost:${port}/${path}`
}

const { env } = process
const {
npm_package_name,
npm_package_config_port
} = env

module.exports = ({
...setId(machineIdSync()),
...setName(npm_package_name),
...setAddress(address()),
...setPort(Number(npm_package_config_port)),

getUrl: getUrlFromPort(npm_package_config_port)
})
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
const { presets } = require('./.babelrc.js');
const consul = require('consul')
const { createReadStream } = require('fs')
const url = require('url')

const { presets } = require('./.babelrc.js')

require('@babel/register')({
presets
});
})

const renderStream = require('./render-stream.js')
const { id, address, name, port } = require('./environment.js')

const url = require('url')
const { createReadStream } = require('fs')
const renderStream = require('./render-stream.js');

const { agent } = consul({
host: 'consul',
promisify: true
})

agent.service.register({
id,
name,
address,
port
})
.catch(() => {
'logowanie do spana'
})

module.exports = (req, res) => {
const pathname = url.parse(req.url).pathname
Expand All @@ -16,18 +34,18 @@ module.exports = (req, res) => {
case '/dist/bundle.js':
res.writeHead(200, jsHeader)
createReadStream('./dist/bundle.js').pipe(res)
break;
break
default:
res.writeHead(200, {
'Content-Type': 'text/html',
'Link': '<http://localhost:80/dist/bundle.js>; rel="fragment-script"'
'Link': '<http://localhost:80/dist/bundle.js> rel="fragment-script"'
})

renderStream().then(({ stream, state }) => {
res.write(`
<script>window.CONTACTS_STATE = ${JSON.stringify(state).replace(/</g, '\\\u003c')}</script>
`);
stream.pipe(res);
});
`)
stream.pipe(res)
})
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "fragment-contacts",
"name": "fragment-react",
"sideEffects": false,
"version": "1.0.0",
"description": "",
Expand All @@ -16,7 +16,10 @@
"dependencies": {
"axios": "^0.18.0",
"classnames": "^2.2.5",
"consul": "^0.34.0",
"ip": "^1.1.5",
"micro": "^9.3.3",
"node-machine-id": "^1.1.10",
"prop-types": "^15.6.2",
"react": "^16.1.1",
"react-dom": "^16.1.1",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
25 changes: 0 additions & 25 deletions packages/fragment-recommendations-vue/index.js

This file was deleted.

8 changes: 0 additions & 8 deletions packages/fragment-simple-vue-test/index.js

This file was deleted.

5 changes: 0 additions & 5 deletions packages/fragment-simple-vue-test/src/entry-server.js

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
28 changes: 28 additions & 0 deletions packages/fragment-vue-client/environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { machineIdSync } = require('node-machine-id')
const { address } = require('ip')


const setId = (id) => ({ id })
const setName = (name) => ({ name })
const setAddress = (address) => ({ address })
const setPort = port => ({ port })

const getUrlFromPort = (port) => (path) => {
// @todo
return `//localhost:${port}/${path}`
}

const { env } = process
const {
npm_package_name,
npm_package_config_port
} = env

module.exports = ({
...setId(machineIdSync()),
...setName(npm_package_name),
...setAddress(address()),
...setPort(Number(npm_package_config_port)),

getUrl: getUrlFromPort(npm_package_config_port)
})
43 changes: 43 additions & 0 deletions packages/fragment-vue-client/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const consul = require('consul')
const url = require('url')
const { createReadStream } = require('fs')

const { id, address, name, port } = require('./environment.js')
const renderStream = require('./render-stream.js')


const bundleStream = createReadStream('./dist/bundle.js')


const { agent } = consul({
host: 'consul',
promisify: true
})

agent.service.register({
id,
name,
address,
port
})
.catch(() => {
'logowanie do spana'
})

module.exports = (req, res) => {
const pathname = url.parse(req.url).pathname
const jsHeader = { 'Content-Type': 'application/javascript' }
switch(pathname) {
case '/dist/bundle.js':
res.writeHead(200, jsHeader)
bundleStream.pipe(res)
break
default:
res.writeHead(200, {
'Content-Type': 'text/html',
'Link': '<http://localhost:80/dist/bundle.js> rel="fragment-script"'
})

renderStream().pipe(res)
}
}
Loading

0 comments on commit a7f8dbc

Please sign in to comment.