refactor: http -> web
This commit is contained in:
parent
c58bf65830
commit
622afb628a
|
@ -75,11 +75,11 @@ At its core, flecks is a collection of modules that use [hooks](packages/core/bu
|
||||||
|
|
||||||
Just to give you an idea of the power of hooks, some will be listed here:
|
Just to give you an idea of the power of hooks, some will be listed here:
|
||||||
|
|
||||||
- [`@flecks/http/server.stream.html`](https://github.com/cha0s/flecks/blob/gh-pages/hooks.md#fleckshttpserverstreamhtml)
|
- [`@flecks/web/server.stream.html`](https://github.com/cha0s/flecks/blob/gh-pages/hooks.md#fleckshttpserverstreamhtml)
|
||||||
> Compose the server-side HTML stream. This is how SSR slides in.
|
> Compose the server-side HTML stream. This is how SSR slides in.
|
||||||
- [`@flecks/docker.containers`](https://github.com/cha0s/flecks/blob/gh-pages/hooks.md#flecksdockercontainers)
|
- [`@flecks/docker.containers`](https://github.com/cha0s/flecks/blob/gh-pages/hooks.md#flecksdockercontainers)
|
||||||
> Define [Docker](https://www.docker.com/) containers to automatically come up next to your app. See [`@flecks/redis`'s implementation](packages/redis/src/containers.js). `@flecks/docker` also generates `Dockerfile` and `docker-compose.yml` and provides the [CLI command](https://github.com/cha0s/flecks/blob/gh-pages/hooks.md#fleckscorecommands) `flecks docker` for even more.
|
> Define [Docker](https://www.docker.com/) containers to automatically come up next to your app. See [`@flecks/redis`'s implementation](packages/redis/src/containers.js). `@flecks/docker` also generates `Dockerfile` and `docker-compose.yml` and provides the [CLI command](https://github.com/cha0s/flecks/blob/gh-pages/hooks.md#fleckscorecommands) `flecks docker` for even more.
|
||||||
- [`@flecks/http/server.request.route`](https://github.com/cha0s/flecks/blob/gh-pages/hooks.md#fleckshttpserverrequestroute)
|
- [`@flecks/web/server.request.route`](https://github.com/cha0s/flecks/blob/gh-pages/hooks.md#fleckshttpserverrequestroute)
|
||||||
> Define [Express](http://expressjs.com/) middleware that runs when an HTTP route is hit.
|
> Define [Express](http://expressjs.com/) middleware that runs when an HTTP route is hit.
|
||||||
- [... and many more on the hook reference page](https://github.com/cha0s/flecks/blob/gh-pages/hooks.md)
|
- [... and many more on the hook reference page](https://github.com/cha0s/flecks/blob/gh-pages/hooks.md)
|
||||||
|
|
||||||
|
|
2
TODO.md
2
TODO.md
|
@ -28,5 +28,5 @@
|
||||||
- [ ] governor fails if not in server up
|
- [ ] governor fails if not in server up
|
||||||
- [ ] redux store provider fails if not in request
|
- [ ] redux store provider fails if not in request
|
||||||
- [ ] client hooks will run on server if they're explicit in `flecks.yml`. Should there be an implicit `!client` when bootstrapping the server?
|
- [ ] client hooks will run on server if they're explicit in `flecks.yml`. Should there be an implicit `!client` when bootstrapping the server?
|
||||||
- [ ] rename `@flecks/http` to `@flecks/web`
|
- [ ] rename `@flecks/web` to `@flecks/web`
|
||||||
- [ ] simultaneous babel compilation across all compiled flecks
|
- [ ] simultaneous babel compilation across all compiled flecks
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
"@flecks/dox": "^1.2.0",
|
"@flecks/dox": "^1.2.0",
|
||||||
"@flecks/fleck": "^1.2.0",
|
"@flecks/fleck": "^1.2.0",
|
||||||
"@flecks/governor": "^1.2.0",
|
"@flecks/governor": "^1.2.0",
|
||||||
"@flecks/http": "^1.2.0",
|
|
||||||
"@flecks/react": "^1.2.0",
|
"@flecks/react": "^1.2.0",
|
||||||
"@flecks/redis": "^1.2.0",
|
"@flecks/redis": "^1.2.0",
|
||||||
"@flecks/redux": "^1.2.0",
|
"@flecks/redux": "^1.2.0",
|
||||||
|
@ -29,6 +28,7 @@
|
||||||
"@flecks/server": "^1.2.0",
|
"@flecks/server": "^1.2.0",
|
||||||
"@flecks/socket": "^1.2.0",
|
"@flecks/socket": "^1.2.0",
|
||||||
"@flecks/user": "^1.2.0",
|
"@flecks/user": "^1.2.0",
|
||||||
|
"@flecks/web": "^1.2.0",
|
||||||
"lerna": "^3.22.1"
|
"lerna": "^3.22.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ export default {
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
'@flecks/db/server.models': Flecks.provide(require.context('./models', false, /\.js$/)),
|
'@flecks/db/server.models': Flecks.provide(require.context('./models', false, /\.js$/)),
|
||||||
'@flecks/http/server.request.route': (flecks) => {
|
'@flecks/web/server.request.route': (flecks) => {
|
||||||
const {http} = flecks.get('@flecks/governor/server');
|
const {http} = flecks.get('@flecks/governor/server');
|
||||||
const limiter = flecks.get('$flecks/governor.http.limiter');
|
const limiter = flecks.get('$flecks/governor.http.limiter');
|
||||||
return async (req, res, next) => {
|
return async (req, res, next) => {
|
||||||
|
@ -56,7 +56,7 @@ export default {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
'@flecks/server.up': async (flecks) => {
|
'@flecks/server.up': async (flecks) => {
|
||||||
if (flecks.fleck('@flecks/http/server')) {
|
if (flecks.fleck('@flecks/web/server')) {
|
||||||
const {http} = flecks.get('@flecks/governor/server');
|
const {http} = flecks.get('@flecks/governor/server');
|
||||||
const limiter = await createLimiter(
|
const limiter = await createLimiter(
|
||||||
flecks,
|
flecks,
|
||||||
|
|
|
@ -12,7 +12,7 @@ export {FlecksContext};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
[Hooks]: {
|
[Hooks]: {
|
||||||
'@flecks/http/client.up': async (flecks) => {
|
'@flecks/web/client.up': async (flecks) => {
|
||||||
const {ssr} = flecks.get('@flecks/react');
|
const {ssr} = flecks.get('@flecks/react');
|
||||||
debug('%sing...', ssr ? 'hydrat' : 'render');
|
debug('%sing...', ssr ? 'hydrat' : 'render');
|
||||||
(ssr ? hydrate : render)(
|
(ssr ? hydrate : render)(
|
||||||
|
|
|
@ -14,7 +14,7 @@ export default {
|
||||||
.prepend('.web.jsx');
|
.prepend('.web.jsx');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
'@flecks/http/server.stream.html': (stream, req, flecks) => (
|
'@flecks/web/server.stream.html': (stream, req, flecks) => (
|
||||||
flecks.get('@flecks/react.ssr') ? ssr(stream, req, flecks) : stream
|
flecks.get('@flecks/react.ssr') ? ssr(stream, req, flecks) : stream
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
|
@ -9,7 +9,7 @@ const debug = D('@flecks/redux/server');
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
[Hooks]: {
|
[Hooks]: {
|
||||||
'@flecks/http/server.request.route': (flecks) => async (req, res, next) => {
|
'@flecks/web/server.request.route': (flecks) => async (req, res, next) => {
|
||||||
const slices = await ensureUniqueReduction(flecks, '@flecks/redux.slices');
|
const slices = await ensureUniqueReduction(flecks, '@flecks/redux.slices');
|
||||||
const reducer = createReducer(flecks, slices);
|
const reducer = createReducer(flecks, slices);
|
||||||
// Let the slices have a(n async) chance to hydrate with server data.
|
// Let the slices have a(n async) chance to hydrate with server data.
|
||||||
|
@ -25,7 +25,7 @@ export default {
|
||||||
req.redux = await configureStore(flecks, reducer, {preloadedState});
|
req.redux = await configureStore(flecks, reducer, {preloadedState});
|
||||||
next();
|
next();
|
||||||
},
|
},
|
||||||
'@flecks/http.config': async (req) => ({
|
'@flecks/web.config': async (req) => ({
|
||||||
'@flecks/redux/client': {
|
'@flecks/redux/client': {
|
||||||
preloadedState: req.redux.getState(),
|
preloadedState: req.redux.getState(),
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,7 +4,7 @@ import SocketClient from './socket';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
[Hooks]: {
|
[Hooks]: {
|
||||||
'@flecks/http/client.up': (flecks) => {
|
'@flecks/web/client.up': (flecks) => {
|
||||||
const socket = new SocketClient(flecks);
|
const socket = new SocketClient(flecks);
|
||||||
flecks.set('$flecks/socket.socket', socket);
|
flecks.set('$flecks/socket.socket', socket);
|
||||||
socket.connect();
|
socket.connect();
|
||||||
|
|
|
@ -17,7 +17,7 @@ export default {
|
||||||
{check: badPacketsCheck},
|
{check: badPacketsCheck},
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
'@flecks/http.config': async (
|
'@flecks/web.config': async (
|
||||||
req,
|
req,
|
||||||
{config: {'@flecks/socket': {'packets.decorate': decorators = ['...']}}},
|
{config: {'@flecks/socket': {'packets.decorate': decorators = ['...']}}},
|
||||||
) => ({
|
) => ({
|
||||||
|
|
|
@ -5,11 +5,11 @@ import Sockets from './sockets';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
[Hooks]: {
|
[Hooks]: {
|
||||||
'@flecks/http/server.request.socket': ({config: {'$flecks/socket.sockets': sockets}}) => (req, res, next) => {
|
'@flecks/web/server.request.socket': ({config: {'$flecks/socket.sockets': sockets}}) => (req, res, next) => {
|
||||||
req.intercom = createIntercom(sockets, 'http');
|
req.intercom = createIntercom(sockets, 'http');
|
||||||
next();
|
next();
|
||||||
},
|
},
|
||||||
'@flecks/http/server.up': async (httpServer, flecks) => {
|
'@flecks/web/server.up': async (httpServer, flecks) => {
|
||||||
const sockets = new Sockets(httpServer, flecks);
|
const sockets = new Sockets(httpServer, flecks);
|
||||||
await sockets.connect();
|
await sockets.connect();
|
||||||
flecks.set('$flecks/socket.sockets', sockets);
|
flecks.set('$flecks/socket.sockets', sockets);
|
||||||
|
|
|
@ -19,7 +19,7 @@ export default {
|
||||||
'@flecks/db/server.models.decorate': (
|
'@flecks/db/server.models.decorate': (
|
||||||
Flecks.decorate(require.context('./models/decorators', false, /\.js$/))
|
Flecks.decorate(require.context('./models/decorators', false, /\.js$/))
|
||||||
),
|
),
|
||||||
'@flecks/http.routes': (flecks) => {
|
'@flecks/web.routes': (flecks) => {
|
||||||
const {failureRedirect, successRedirect} = flecks.get('@flecks/user/local/server');
|
const {failureRedirect, successRedirect} = flecks.get('@flecks/user/local/server');
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,10 +7,10 @@ const debug = D('@flecks/user/passport');
|
||||||
export default {
|
export default {
|
||||||
[Hooks]: {
|
[Hooks]: {
|
||||||
'@flecks/db/server.models': Flecks.provide(require.context('./models', false, /\.js$/)),
|
'@flecks/db/server.models': Flecks.provide(require.context('./models', false, /\.js$/)),
|
||||||
'@flecks/http/server.request.route': (flecks) => (req, res, next) => {
|
'@flecks/web/server.request.route': (flecks) => (req, res, next) => {
|
||||||
debug('@flecks/http/server.request.route: passport.initialize()');
|
debug('@flecks/web/server.request.route: passport.initialize()');
|
||||||
passport.initialize()(req, res, () => {
|
passport.initialize()(req, res, () => {
|
||||||
debug('@flecks/http/server.request.route: passport.session()');
|
debug('@flecks/web/server.request.route: passport.session()');
|
||||||
passport.session()(req, res, () => {
|
passport.session()(req, res, () => {
|
||||||
if (!req.user) {
|
if (!req.user) {
|
||||||
const {User} = flecks.get('$flecks/db.models');
|
const {User} = flecks.get('$flecks/db.models');
|
||||||
|
@ -21,7 +21,7 @@ export default {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
'@flecks/http.routes': () => [
|
'@flecks/web.routes': () => [
|
||||||
{
|
{
|
||||||
method: 'get',
|
method: 'get',
|
||||||
path: '/auth/logout',
|
path: '/auth/logout',
|
||||||
|
|
|
@ -16,16 +16,16 @@ export default {
|
||||||
'Set the FLECKS_ENV_FLECKS_USER_SESSION_SERVER_cookieSecret environment variable!'
|
'Set the FLECKS_ENV_FLECKS_USER_SESSION_SERVER_cookieSecret environment variable!'
|
||||||
),
|
),
|
||||||
}),
|
}),
|
||||||
'@flecks/http/server.request.route': (flecks) => {
|
'@flecks/web/server.request.route': (flecks) => {
|
||||||
const urle = express.urlencoded({extended: true});
|
const urle = express.urlencoded({extended: true});
|
||||||
return (req, res, next) => {
|
return (req, res, next) => {
|
||||||
debug('@flecks/http/server.request.route: express.urlencoded()');
|
debug('@flecks/web/server.request.route: express.urlencoded()');
|
||||||
urle(req, res, (error) => {
|
urle(req, res, (error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
next(error);
|
next(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
debug('@flecks/http/server.request.route: session()');
|
debug('@flecks/web/server.request.route: session()');
|
||||||
flecks.get('$flecks/user.session')(req, res, (error) => {
|
flecks.get('$flecks/user.session')(req, res, (error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
next(error);
|
next(error);
|
||||||
|
|
|
@ -21,7 +21,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
||||||
|
|
||||||
## [1.2.1](https://github.com/cha0s/flecks/compare/v1.2.0...v1.2.1) (2022-03-08)
|
## [1.2.1](https://github.com/cha0s/flecks/compare/v1.2.0...v1.2.1) (2022-03-08)
|
||||||
|
|
||||||
**Note:** Version bump only for package @flecks/http
|
**Note:** Version bump only for package @flecks/web
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
||||||
|
|
||||||
## [1.1.1](https://github.com/cha0s/flecks/compare/v1.1.0...v1.1.1) (2022-02-28)
|
## [1.1.1](https://github.com/cha0s/flecks/compare/v1.1.0...v1.1.1) (2022-02-28)
|
||||||
|
|
||||||
**Note:** Version bump only for package @flecks/http
|
**Note:** Version bump only for package @flecks/web
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,4 +67,4 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
||||||
|
|
||||||
## [1.0.2](https://github.com/cha0s/flecks/compare/v1.0.1...v1.0.2) (2022-02-28)
|
## [1.0.2](https://github.com/cha0s/flecks/compare/v1.0.1...v1.0.2) (2022-02-28)
|
||||||
|
|
||||||
**Note:** Version bump only for package @flecks/http
|
**Note:** Version bump only for package @flecks/web
|
|
@ -5,14 +5,14 @@ export default {
|
||||||
/**
|
/**
|
||||||
* Define sequential actions to run when the client comes up.
|
* Define sequential actions to run when the client comes up.
|
||||||
*/
|
*/
|
||||||
'@flecks/http/client.up': async () => {
|
'@flecks/web/client.up': async () => {
|
||||||
await youCanDoAsyncThingsHere();
|
await youCanDoAsyncThingsHere();
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Override flecks configuration sent to client flecks.
|
* Override flecks configuration sent to client flecks.
|
||||||
* @param {http.ClientRequest} req The HTTP request object.
|
* @param {http.ClientRequest} req The HTTP request object.
|
||||||
*/
|
*/
|
||||||
'@flecks/http.config': (req) => ({
|
'@flecks/web.config': (req) => ({
|
||||||
someClientFleck: {
|
someClientFleck: {
|
||||||
someConfig: req.someConfig,
|
someConfig: req.someConfig,
|
||||||
},
|
},
|
||||||
|
@ -20,7 +20,7 @@ export default {
|
||||||
/**
|
/**
|
||||||
* Define HTTP routes.
|
* Define HTTP routes.
|
||||||
*/
|
*/
|
||||||
'@flecks/http.routes': () => [
|
'@flecks/web.routes': () => [
|
||||||
{
|
{
|
||||||
method: 'get',
|
method: 'get',
|
||||||
path: '/some-path',
|
path: '/some-path',
|
||||||
|
@ -33,14 +33,14 @@ export default {
|
||||||
/**
|
/**
|
||||||
* Define middleware to run when a route is matched.
|
* Define middleware to run when a route is matched.
|
||||||
*/
|
*/
|
||||||
'@flecks/http/server.request.route': () => (req, res, next) => {
|
'@flecks/web/server.request.route': () => (req, res, next) => {
|
||||||
// Express-style route middleware...
|
// Express-style route middleware...
|
||||||
next();
|
next();
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Define middleware to run when an HTTP socket connection is established.
|
* Define middleware to run when an HTTP socket connection is established.
|
||||||
*/
|
*/
|
||||||
'@flecks/http/server.request.socket': () => (req, res, next) => {
|
'@flecks/web/server.request.socket': () => (req, res, next) => {
|
||||||
// Express-style route middleware...
|
// Express-style route middleware...
|
||||||
next();
|
next();
|
||||||
},
|
},
|
||||||
|
@ -49,13 +49,13 @@ export default {
|
||||||
* @param {stream.Readable} stream The HTML stream.
|
* @param {stream.Readable} stream The HTML stream.
|
||||||
* @param {http.ClientRequest} req The HTTP request object.
|
* @param {http.ClientRequest} req The HTTP request object.
|
||||||
*/
|
*/
|
||||||
'@flecks/http/server.stream.html': (stream, req) => {
|
'@flecks/web/server.stream.html': (stream, req) => {
|
||||||
return stream.pipe(myTransformStream);
|
return stream.pipe(myTransformStream);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Define sequential actions to run when the HTTP server comes up.
|
* Define sequential actions to run when the HTTP server comes up.
|
||||||
*/
|
*/
|
||||||
'@flecks/http/server.up': async () => {
|
'@flecks/web/server.up': async () => {
|
||||||
await youCanDoAsyncThingsHere();
|
await youCanDoAsyncThingsHere();
|
||||||
},
|
},
|
||||||
},
|
},
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "@flecks/http",
|
"name": "@flecks/web",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/cha0s/flecks.git",
|
"url": "https://github.com/cha0s/flecks.git",
|
|
@ -11,12 +11,12 @@ const progress = new Progress(window);
|
||||||
(async () => {
|
(async () => {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log(`flecks client v${version} loading runtime...`);
|
console.log(`flecks client v${version} loading runtime...`);
|
||||||
const config = window[Symbol.for('@flecks/http.config')];
|
const config = window[Symbol.for('@flecks/web.config')];
|
||||||
const debug = D(config['@flecks/core']?.id || 'flecks');
|
const debug = D(config['@flecks/core']?.id || 'flecks');
|
||||||
debug('loading runtime...');
|
debug('loading runtime...');
|
||||||
const {default: loader} = await __non_webpack_import__(
|
const {default: loader} = await __non_webpack_import__(
|
||||||
/* @preserve webpackChunkName: "flecks-runtime" */
|
/* @preserve webpackChunkName: "flecks-runtime" */
|
||||||
'@flecks/http/runtime',
|
'@flecks/web/runtime',
|
||||||
);
|
);
|
||||||
const runtime = await loader(progress.update.bind(progress));
|
const runtime = await loader(progress.update.bind(progress));
|
||||||
progress.finish();
|
progress.finish();
|
||||||
|
@ -24,7 +24,7 @@ const progress = new Progress(window);
|
||||||
const flecks = new Flecks(runtime);
|
const flecks = new Flecks(runtime);
|
||||||
window.flecks = flecks;
|
window.flecks = flecks;
|
||||||
try {
|
try {
|
||||||
await flecks.up('@flecks/http/client.up');
|
await flecks.up('@flecks/web/client.up');
|
||||||
debug('up!');
|
debug('up!');
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
|
@ -1,6 +1,6 @@
|
||||||
import {D} from '@flecks/core';
|
import {D} from '@flecks/core';
|
||||||
|
|
||||||
const debug = D('@flecks/http/progress');
|
const debug = D('@flecks/web/progress');
|
||||||
|
|
||||||
export default class Progress {
|
export default class Progress {
|
||||||
|
|
|
@ -7,7 +7,7 @@ module.exports = (flecks) => (neutrino) => {
|
||||||
devPublic,
|
devPublic,
|
||||||
devStats,
|
devStats,
|
||||||
port,
|
port,
|
||||||
} = flecks.get('@flecks/http/server');
|
} = flecks.get('@flecks/web/server');
|
||||||
neutrino.use(devServer({
|
neutrino.use(devServer({
|
||||||
historyApiFallback: {
|
historyApiFallback: {
|
||||||
disableDotRule: true,
|
disableDotRule: true,
|
|
@ -19,7 +19,7 @@ module.exports = async (flecks) => {
|
||||||
},
|
},
|
||||||
use: [
|
use: [
|
||||||
({config, options}) => {
|
({config, options}) => {
|
||||||
const dll = flecks.get('@flecks/http/server.dll');
|
const dll = flecks.get('@flecks/web/server.dll');
|
||||||
if (dll.length > 0) {
|
if (dll.length > 0) {
|
||||||
// Build the library and manifest.
|
// Build the library and manifest.
|
||||||
config.context(options.root);
|
config.context(options.root);
|
||||||
|
@ -65,7 +65,7 @@ module.exports = async (flecks) => {
|
||||||
config.resolve.modules
|
config.resolve.modules
|
||||||
.merge([join(FLECKS_CORE_ROOT, 'node_modules')]);
|
.merge([join(FLECKS_CORE_ROOT, 'node_modules')]);
|
||||||
// Reporting.
|
// Reporting.
|
||||||
config.stats(flecks.get('@flecks/http/server.stats'));
|
config.stats(flecks.get('@flecks/web/server.stats'));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
],
|
],
|
|
@ -20,7 +20,7 @@ module.exports = async (flecks) => {
|
||||||
// Build configuration.
|
// Build configuration.
|
||||||
const build = async () => {
|
const build = async () => {
|
||||||
const root = await realpath(
|
const root = await realpath(
|
||||||
dirname(R.resolve(join(flecks.resolve('@flecks/http'), 'entry.js'))),
|
dirname(R.resolve(join(flecks.resolve('@flecks/web'), 'entry.js'))),
|
||||||
);
|
);
|
||||||
return (neutrino) => {
|
return (neutrino) => {
|
||||||
const {config, options} = neutrino;
|
const {config, options} = neutrino;
|
||||||
|
@ -38,7 +38,7 @@ module.exports = async (flecks) => {
|
||||||
entry: join(root, 'server', 'build', 'tests'),
|
entry: join(root, 'server', 'build', 'tests'),
|
||||||
title: 'Testbed',
|
title: 'Testbed',
|
||||||
};
|
};
|
||||||
options.output = join(originalOutput, flecks.get('@flecks/http/server.output'));
|
options.output = join(originalOutput, flecks.get('@flecks/web/server.output'));
|
||||||
// Load HTML.
|
// Load HTML.
|
||||||
neutrino.use(htmlLoader());
|
neutrino.use(htmlLoader());
|
||||||
Object.entries(options.mains).forEach(([name, mainsConfig]) => {
|
Object.entries(options.mains).forEach(([name, mainsConfig]) => {
|
||||||
|
@ -137,12 +137,12 @@ module.exports = async (flecks) => {
|
||||||
config.resolve.modules
|
config.resolve.modules
|
||||||
.merge([join(FLECKS_CORE_ROOT, 'node_modules')]);
|
.merge([join(FLECKS_CORE_ROOT, 'node_modules')]);
|
||||||
// Reporting.
|
// Reporting.
|
||||||
config.stats(flecks.get('@flecks/http/server.stats'));
|
config.stats(flecks.get('@flecks/web/server.stats'));
|
||||||
// Inline the main entrypoint (nice for FCP).
|
// Inline the main entrypoint (nice for FCP).
|
||||||
config
|
config
|
||||||
.plugin('inline-chunks')
|
.plugin('inline-chunks')
|
||||||
.use(InlineChunkHtmlPlugin, [HtmlWebpackPlugin, [/^assets\/index(\.[^.]*)?\.js$/]]);
|
.use(InlineChunkHtmlPlugin, [HtmlWebpackPlugin, [/^assets\/index(\.[^.]*)?\.js$/]]);
|
||||||
const dll = flecks.get('@flecks/http/server.dll');
|
const dll = flecks.get('@flecks/web/server.dll');
|
||||||
if (!isProduction && dll.length > 0) {
|
if (!isProduction && dll.length > 0) {
|
||||||
const manifest = join(
|
const manifest = join(
|
||||||
FLECKS_CORE_ROOT,
|
FLECKS_CORE_ROOT,
|
|
@ -8,7 +8,7 @@ const {D} = require('@flecks/core');
|
||||||
const {Flecks, require: R} = require('@flecks/core/server');
|
const {Flecks, require: R} = require('@flecks/core/server');
|
||||||
const glob = require('glob');
|
const glob = require('glob');
|
||||||
|
|
||||||
const debug = D('@flecks/http/runtime');
|
const debug = D('@flecks/web/runtime');
|
||||||
|
|
||||||
module.exports = async (flecks) => {
|
module.exports = async (flecks) => {
|
||||||
debug('bootstrapping flecks...');
|
debug('bootstrapping flecks...');
|
||||||
|
@ -41,12 +41,12 @@ module.exports = async (flecks) => {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.filter((filename) => !!filename);
|
.filter((filename) => !!filename);
|
||||||
const runtime = await realpath(R.resolve(join(httpFlecks.resolve('@flecks/http'), 'runtime')));
|
const runtime = await realpath(R.resolve(join(httpFlecks.resolve('@flecks/web'), 'runtime')));
|
||||||
const fullresolve = (fleck, path) => realpath(R.resolve(join(httpFlecks.resolve(fleck), path)));
|
const fullresolve = (fleck, path) => realpath(R.resolve(join(httpFlecks.resolve(fleck), path)));
|
||||||
const entry = await fullresolve('@flecks/http', 'entry');
|
const entry = await fullresolve('@flecks/web', 'entry');
|
||||||
const importLoader = await fullresolve('@flecks/http', 'import-loader');
|
const importLoader = await fullresolve('@flecks/web', 'import-loader');
|
||||||
const tests = await realpath(R.resolve(
|
const tests = await realpath(R.resolve(
|
||||||
join(httpFlecks.resolve('@flecks/http'), 'server', 'build', 'tests'),
|
join(httpFlecks.resolve('@flecks/web'), 'server', 'build', 'tests'),
|
||||||
));
|
));
|
||||||
const testsSource = (await readFile(tests)).toString();
|
const testsSource = (await readFile(tests)).toString();
|
||||||
return (neutrino) => {
|
return (neutrino) => {
|
||||||
|
@ -56,7 +56,7 @@ module.exports = async (flecks) => {
|
||||||
const paths = Object.entries(resolver);
|
const paths = Object.entries(resolver);
|
||||||
const source = [
|
const source = [
|
||||||
'module.exports = (update) => (async () => ({',
|
'module.exports = (update) => (async () => ({',
|
||||||
" config: window[Symbol.for('@flecks/http.config')],",
|
" config: window[Symbol.for('@flecks/web.config')],",
|
||||||
' flecks: Object.fromEntries(await Promise.all([',
|
' flecks: Object.fromEntries(await Promise.all([',
|
||||||
paths
|
paths
|
||||||
.map(([path]) => [
|
.map(([path]) => [
|
||||||
|
@ -92,7 +92,7 @@ module.exports = async (flecks) => {
|
||||||
source: source.join('\n'),
|
source: source.join('\n'),
|
||||||
});
|
});
|
||||||
config.resolve.alias
|
config.resolve.alias
|
||||||
.set('@flecks/http/runtime$', runtime);
|
.set('@flecks/web/runtime$', runtime);
|
||||||
flecks.runtimeCompiler(httpFlecks.resolver, 'http', neutrino);
|
flecks.runtimeCompiler(httpFlecks.resolver, 'http', neutrino);
|
||||||
// Handle runtime import.
|
// Handle runtime import.
|
||||||
config.module
|
config.module
|
||||||
|
@ -138,7 +138,7 @@ module.exports = async (flecks) => {
|
||||||
.loader(runtime)
|
.loader(runtime)
|
||||||
.options({
|
.options({
|
||||||
source: testsSource.replace(
|
source: testsSource.replace(
|
||||||
"await import('@flecks/http/tests');",
|
"await import('@flecks/web/tests');",
|
||||||
[
|
[
|
||||||
'const tests = {};',
|
'const tests = {};',
|
||||||
Object.entries(
|
Object.entries(
|
|
@ -9,7 +9,7 @@ window.document.body.appendChild(mochaDiv);
|
||||||
mocha.setup('bdd');
|
mocha.setup('bdd');
|
||||||
|
|
||||||
// eslint-disable-next-line import/no-extraneous-dependencies, import/no-unresolved
|
// eslint-disable-next-line import/no-extraneous-dependencies, import/no-unresolved
|
||||||
await import('@flecks/http/tests');
|
await import('@flecks/web/tests');
|
||||||
|
|
||||||
mocha.run();
|
mocha.run();
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import {Transform} from 'stream';
|
import {Transform} from 'stream';
|
||||||
|
|
||||||
const config = async (flecks, req) => {
|
const config = async (flecks, req) => {
|
||||||
const httpConfig = await flecks.invokeMergeAsync('@flecks/http.config', req);
|
const httpConfig = await flecks.invokeMergeAsync('@flecks/web.config', req);
|
||||||
const {config} = flecks.get('$flecks/http.flecks');
|
const {config} = flecks.get('$flecks/web.flecks');
|
||||||
return Object.keys(config)
|
return Object.keys(config)
|
||||||
.filter((path) => !path.startsWith('$'))
|
.filter((path) => !path.startsWith('$'))
|
||||||
.filter((path) => !path.endsWith('/server'))
|
.filter((path) => !path.endsWith('/server'))
|
||||||
|
@ -20,7 +20,7 @@ const config = async (flecks, req) => {
|
||||||
|
|
||||||
export const configSource = async (flecks, req) => {
|
export const configSource = async (flecks, req) => {
|
||||||
const codedConfig = encodeURIComponent(JSON.stringify(await config(flecks, req)));
|
const codedConfig = encodeURIComponent(JSON.stringify(await config(flecks, req)));
|
||||||
return `window[Symbol.for('@flecks/http.config')] = JSON.parse(decodeURIComponent("${
|
return `window[Symbol.for('@flecks/web.config')] = JSON.parse(decodeURIComponent("${
|
||||||
codedConfig
|
codedConfig
|
||||||
}"));`;
|
}"));`;
|
||||||
};
|
};
|
|
@ -13,33 +13,33 @@ const {
|
||||||
NODE_ENV,
|
NODE_ENV,
|
||||||
} = process.env;
|
} = process.env;
|
||||||
|
|
||||||
const debug = D('@flecks/http/server/http');
|
const debug = D('@flecks/web/server/http');
|
||||||
|
|
||||||
const deliverHtmlStream = (stream, flecks, req, res) => {
|
const deliverHtmlStream = (stream, flecks, req, res) => {
|
||||||
flecks.invokeComposed('@flecks/http/server.stream.html', stream, req).pipe(res);
|
flecks.invokeComposed('@flecks/web/server.stream.html', stream, req).pipe(res);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createHttpServer = async (flecks) => {
|
export const createHttpServer = async (flecks) => {
|
||||||
const {trust} = flecks.get('@flecks/http/server');
|
const {trust} = flecks.get('@flecks/web/server');
|
||||||
const {
|
const {
|
||||||
devHost,
|
devHost,
|
||||||
devPort,
|
devPort,
|
||||||
host,
|
host,
|
||||||
output,
|
output,
|
||||||
port,
|
port,
|
||||||
} = flecks.get('@flecks/http/server');
|
} = flecks.get('@flecks/web/server');
|
||||||
const app = express();
|
const app = express();
|
||||||
app.set('trust proxy', trust);
|
app.set('trust proxy', trust);
|
||||||
const httpServer = createServer(app);
|
const httpServer = createServer(app);
|
||||||
httpServer.app = app;
|
httpServer.app = app;
|
||||||
flecks.set('$flecks/http/server.instance', httpServer);
|
flecks.set('$flecks/web/server.instance', httpServer);
|
||||||
// Compression. heheh
|
// Compression. heheh
|
||||||
app.use(compression({level: 'production' === NODE_ENV ? 6 : 9}));
|
app.use(compression({level: 'production' === NODE_ENV ? 6 : 9}));
|
||||||
// Socket connection.
|
// Socket connection.
|
||||||
app.use(flecks.makeMiddleware('@flecks/http/server.request.socket'));
|
app.use(flecks.makeMiddleware('@flecks/web/server.request.socket'));
|
||||||
// Routes.
|
// Routes.
|
||||||
const routeMiddleware = flecks.makeMiddleware('@flecks/http/server.request.route');
|
const routeMiddleware = flecks.makeMiddleware('@flecks/web/server.request.route');
|
||||||
const routes = flatten(flecks.invokeFlat('@flecks/http.routes'));
|
const routes = flatten(flecks.invokeFlat('@flecks/web.routes'));
|
||||||
routes.forEach(({method, path, middleware}) => app[method](path, routeMiddleware, middleware));
|
routes.forEach(({method, path, middleware}) => app[method](path, routeMiddleware, middleware));
|
||||||
// In development mode, create a proxy to the webpack-dev-server.
|
// In development mode, create a proxy to the webpack-dev-server.
|
||||||
if ('production' !== NODE_ENV) {
|
if ('production' !== NODE_ENV) {
|
||||||
|
@ -117,7 +117,7 @@ export const createHttpServer = async (flecks) => {
|
||||||
reject(error);
|
reject(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await Promise.all(flecks.invokeFlat('@flecks/http/server.up', httpServer));
|
await Promise.all(flecks.invokeFlat('@flecks/web/server.up', httpServer));
|
||||||
debug('HTTP server up @ %s!', [host, port].filter((e) => !!e).join(':'));
|
debug('HTTP server up @ %s!', [host, port].filter((e) => !!e).join(':'));
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
|
@ -14,7 +14,7 @@ const {
|
||||||
FLECKS_CORE_ROOT = process.cwd(),
|
FLECKS_CORE_ROOT = process.cwd(),
|
||||||
} = process.env;
|
} = process.env;
|
||||||
|
|
||||||
const debug = D('@flecks/http/server');
|
const debug = D('@flecks/web/server');
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
[Hooks]: {
|
[Hooks]: {
|
||||||
|
@ -69,7 +69,7 @@ export default {
|
||||||
},
|
},
|
||||||
'@flecks/core.build.alter': async (neutrinoConfigs, flecks) => {
|
'@flecks/core.build.alter': async (neutrinoConfigs, flecks) => {
|
||||||
// Don't build if there's a fleck target.
|
// Don't build if there's a fleck target.
|
||||||
if (neutrinoConfigs.fleck && !flecks.get('@flecks/http/server.forceBuildWithFleck')) {
|
if (neutrinoConfigs.fleck && !flecks.get('@flecks/web/server.forceBuildWithFleck')) {
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
delete neutrinoConfigs.http;
|
delete neutrinoConfigs.http;
|
||||||
return;
|
return;
|
||||||
|
@ -81,7 +81,7 @@ export default {
|
||||||
delete neutrinoConfigs['http-vendor'];
|
delete neutrinoConfigs['http-vendor'];
|
||||||
}
|
}
|
||||||
// Only build if something actually changed.
|
// Only build if something actually changed.
|
||||||
const dll = flecks.get('@flecks/http/server.dll');
|
const dll = flecks.get('@flecks/web/server.dll');
|
||||||
if (dll.length > 0) {
|
if (dll.length > 0) {
|
||||||
const manifest = join(
|
const manifest = join(
|
||||||
FLECKS_CORE_ROOT,
|
FLECKS_CORE_ROOT,
|
||||||
|
@ -224,13 +224,13 @@ export default {
|
||||||
platforms: ['client', '!server'],
|
platforms: ['client', '!server'],
|
||||||
});
|
});
|
||||||
debug('bootstrapped');
|
debug('bootstrapped');
|
||||||
flecks.set('$flecks/http.flecks', httpFlecks);
|
flecks.set('$flecks/web.flecks', httpFlecks);
|
||||||
},
|
},
|
||||||
'@flecks/core.targets': (flecks) => [
|
'@flecks/core.targets': (flecks) => [
|
||||||
'http',
|
'http',
|
||||||
...(flecks.get('@flecks/http/server.dll').length > 0 ? ['http-vendor'] : []),
|
...(flecks.get('@flecks/web/server.dll').length > 0 ? ['http-vendor'] : []),
|
||||||
],
|
],
|
||||||
'@flecks/http.routes': (flecks) => [
|
'@flecks/web.routes': (flecks) => [
|
||||||
{
|
{
|
||||||
method: 'get',
|
method: 'get',
|
||||||
path: '/flecks.config.js',
|
path: '/flecks.config.js',
|
||||||
|
@ -240,10 +240,10 @@ export default {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
'@flecks/http/server.stream.html': inlineConfig,
|
'@flecks/web/server.stream.html': inlineConfig,
|
||||||
'@flecks/server.up': (flecks) => createHttpServer(flecks),
|
'@flecks/server.up': (flecks) => createHttpServer(flecks),
|
||||||
'@flecks/repl.context': (flecks) => ({
|
'@flecks/repl.context': (flecks) => ({
|
||||||
httpServer: flecks.get('$flecks/http/server.instance'),
|
httpServer: flecks.get('$flecks/web/server.instance'),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user