chore: finishing up http -> web migration

This commit is contained in:
cha0s 2022-03-22 20:43:05 -05:00
parent 9b68ab87af
commit 2511e90b70
8 changed files with 46 additions and 46 deletions

View File

@ -12,7 +12,7 @@ export default {
* All keys used to determine fingerprint.
*/
keys: ['ip'],
http: {
web: {
keys: ['ip'],
points: 60,
duration: 30,
@ -27,8 +27,8 @@ export default {
}),
'@flecks/db/server.models': Flecks.provide(require.context('./models', false, /\.js$/)),
'@flecks/web/server.request.route': (flecks) => {
const {http} = flecks.get('@flecks/governor/server');
const limiter = flecks.get('$flecks/governor.http.limiter');
const {web} = flecks.get('@flecks/governor/server');
const limiter = flecks.get('$flecks/governor.web.limiter');
return async (req, res, next) => {
const {Ban} = flecks.get('$flecks/db.models');
try {
@ -48,7 +48,7 @@ export default {
next();
}
catch (error) {
const {ttl, keys} = http;
const {ttl, keys} = web;
const ban = Ban.fromRequest(req, keys, ttl);
await Ban.create({...ban});
res.status(429).send(`<pre>${Ban.format([ban])}</pre>`);
@ -57,15 +57,15 @@ export default {
},
'@flecks/server.up': async (flecks) => {
if (flecks.fleck('@flecks/web/server')) {
const {http} = flecks.get('@flecks/governor/server');
const {web} = flecks.get('@flecks/governor/server');
const limiter = await createLimiter(
flecks,
{
keyPrefix: '@flecks/governor.http.request.route',
...http,
keyPrefix: '@flecks/governor.web.request.route',
...web,
},
);
flecks.set('$flecks/governor.http.limiter', limiter);
flecks.set('$flecks/governor.web.limiter', limiter);
}
if (flecks.fleck('@flecks/socket/server')) {
const {[ByType]: Packets} = flecks.get('$flecks/socket.packets');

View File

@ -6,7 +6,7 @@ import Sockets from './sockets';
export default {
[Hooks]: {
'@flecks/web/server.request.socket': ({config: {'$flecks/socket.sockets': sockets}}) => (req, res, next) => {
req.intercom = createIntercom(sockets, 'http');
req.intercom = createIntercom(sockets, 'web');
next();
},
'@flecks/web/server.up': async (httpServer, flecks) => {

View File

@ -3,7 +3,7 @@
"repository": {
"type": "git",
"url": "https://github.com/cha0s/flecks.git",
"directory": "packages/http"
"directory": "packages/web"
},
"publishConfig": {
"access": "public"
@ -30,12 +30,12 @@
"server/build/postcss.config.js",
"server/build/postcss.config.js.map",
"server/build/template.ejs",
"server/build/http.neutrinorc.js",
"server/build/http.neutrinorc.js.map",
"server/build/http-vendor.neutrinorc.js",
"server/build/http-vendor.neutrinorc.js.map",
"server/build/tests.js",
"server/build/tests.js.map",
"server/build/web.neutrinorc.js",
"server/build/web.neutrinorc.js.map",
"server/build/web-vendor.neutrinorc.js",
"server/build/web-vendor.neutrinorc.js.map",
"src",
"tests.js",
"tests.js.map"

View File

@ -11,7 +11,7 @@ const augmentBuild = (target, config, flecks) => {
extract.enabled = false;
style.injectType = 'lazyStyleTag';
}
if ('http' === target) {
if ('web' === target) {
extract.enabled = isProduction;
style.injectType = 'styleTag';
}

View File

@ -12,14 +12,14 @@ const debug = D('@flecks/web/runtime');
module.exports = async (flecks) => {
debug('bootstrapping flecks...');
const httpFlecks = Flecks.bootstrap({
const webFlecks = Flecks.bootstrap({
platforms: ['client', '!server'],
});
debug('bootstrapped');
const rootMap = {};
Object.keys(httpFlecks.resolver)
Object.keys(webFlecks.resolver)
.forEach((fleck) => {
rootMap[httpFlecks.root(fleck)] = fleck;
rootMap[webFlecks.root(fleck)] = fleck;
});
const roots = Object.entries(rootMap)
.map(([root, fleck]) => (
@ -41,14 +41,14 @@ module.exports = async (flecks) => {
)
)
.filter((filename) => !!filename);
const runtime = await realpath(R.resolve(join(httpFlecks.resolve('@flecks/web'), 'runtime')));
const runtime = await realpath(R.resolve(join(webFlecks.resolve('@flecks/web'), 'runtime')));
const tests = await realpath(R.resolve(
join(httpFlecks.resolve('@flecks/web'), 'server', 'build', 'tests'),
join(webFlecks.resolve('@flecks/web'), 'server', 'build', 'tests'),
));
const testsSource = (await readFile(tests)).toString();
return (neutrino) => {
const {config} = neutrino;
const {resolver} = httpFlecks;
const {resolver} = webFlecks;
const isProduction = 'production' === config.get('mode');
const paths = Object.entries(resolver);
const source = [
@ -83,16 +83,16 @@ module.exports = async (flecks) => {
config.module
.rule(runtime)
.test(runtime)
.use('runtime/http')
.use('runtime/web')
.loader(runtime)
.options({
source: source.join('\n'),
});
config.resolve.alias
.set('@flecks/web/runtime$', runtime);
flecks.runtimeCompiler(httpFlecks.resolver, 'http', neutrino);
flecks.runtimeCompiler(webFlecks.resolver, 'web', neutrino);
// Aliases.
const aliases = httpFlecks.aliases();
const aliases = webFlecks.aliases();
if (Object.keys(aliases).length > 0) {
Object.entries(aliases)
.forEach(([from, to]) => {
@ -113,10 +113,10 @@ module.exports = async (flecks) => {
glob.sync(join(root, 'test/*.js'))
.map((path) => [fleck, path])
));
for (let i = 0; i < httpFlecks.platforms.length; ++i) {
for (let i = 0; i < webFlecks.platforms.length; ++i) {
testPaths.push(
...(
glob.sync(join(root, `test/platforms/${httpFlecks.platforms[i]}/*.js`))
glob.sync(join(root, `test/platforms/${webFlecks.platforms[i]}/*.js`))
.map((path) => [fleck, path])
),
);

View File

@ -34,8 +34,8 @@ module.exports = async (flecks) => {
[
{
context: options.root,
path: join(options.output, 'http-vendor.manifest.json'),
name: 'flecks_http_vendor',
path: join(options.output, 'web-vendor.manifest.json'),
name: 'flecks_web_vendor',
},
],
);
@ -44,8 +44,8 @@ module.exports = async (flecks) => {
.devtool('cheap-module-source-map');
config.output
.path(options.output)
.library('flecks_http_vendor')
.filename('http-vendor.js');
.library('flecks_web_vendor')
.filename('web-vendor.js');
config.node
.set('fs', 'empty');
// Resolution.

View File

@ -29,7 +29,7 @@ module.exports = async (flecks) => {
config
.plugin('environment')
.use(EnvironmentPlugin, [{
FLECKS_CORE_BUILD_TARGET: 'http',
FLECKS_CORE_BUILD_TARGET: 'web',
}]);
// Entrypoints.
const {output: originalOutput} = options;
@ -149,7 +149,7 @@ module.exports = async (flecks) => {
'node_modules',
'.cache',
'flecks',
'http-vendor',
'web-vendor',
);
config
.plugin('wait-for-manifest')

View File

@ -23,14 +23,14 @@ export default {
// Don't build if there's a fleck target.
if (neutrinoConfigs.fleck && !flecks.get('@flecks/web/server.forceBuildWithFleck')) {
// eslint-disable-next-line no-param-reassign
delete neutrinoConfigs.http;
delete neutrinoConfigs.web;
return;
}
// Only build vendor in dev.
if (neutrinoConfigs['http-vendor']) {
if (neutrinoConfigs['web-vendor']) {
if (process.argv.find((arg) => 'production' === arg)) {
// eslint-disable-next-line no-param-reassign
delete neutrinoConfigs['http-vendor'];
delete neutrinoConfigs['web-vendor'];
}
// Only build if something actually changed.
const dll = flecks.get('@flecks/web/server.dll');
@ -40,7 +40,7 @@ export default {
'node_modules',
'.cache',
'flecks',
'http-vendor.manifest.json',
'web-vendor.manifest.json',
);
let timestamp = 0;
try {
@ -64,15 +64,15 @@ export default {
}
if (timestamp > latest) {
// eslint-disable-next-line no-param-reassign
delete neutrinoConfigs['http-vendor'];
delete neutrinoConfigs['web-vendor'];
}
else if (timestamp > 0) {
await unlink(manifest);
}
}
}
// Bail if there's no http build.
if (!neutrinoConfigs.http) {
// Bail if there's no web build.
if (!neutrinoConfigs.web) {
return;
}
// Bail if the build isn't watching.
@ -90,13 +90,13 @@ export default {
cmd,
{
env: {
FLECKS_CORE_BUILD_LIST: 'http',
FLECKS_CORE_BUILD_LIST: 'web',
},
},
);
// Remove the build config since we're handing off to WDS.
// eslint-disable-next-line no-param-reassign
delete neutrinoConfigs.http;
delete neutrinoConfigs.web;
},
'@flecks/core.build.config': () => [
/**
@ -148,7 +148,7 @@ export default {
/**
* Build path.
*/
output: 'http',
output: 'web',
/**
* Port to bind.
*/
@ -171,16 +171,16 @@ export default {
}),
'@flecks/core.starting': (flecks) => {
debug('bootstrapping flecks...');
const httpFlecks = Flecks.bootstrap({
const webFlecks = Flecks.bootstrap({
config: flecks.config,
platforms: ['client', '!server'],
});
debug('bootstrapped');
flecks.set('$flecks/web.flecks', httpFlecks);
flecks.set('$flecks/web.flecks', webFlecks);
},
'@flecks/core.targets': (flecks) => [
'http',
...(flecks.get('@flecks/web/server.dll').length > 0 ? ['http-vendor'] : []),
'web',
...(flecks.get('@flecks/web/server.dll').length > 0 ? ['web-vendor'] : []),
],
'@flecks/web.routes': (flecks) => [
{