refactor: environment

This commit is contained in:
cha0s 2022-02-28 05:16:24 -06:00
parent 8ed96484b9
commit d6d7260799
36 changed files with 170 additions and 165 deletions

View File

@ -8,7 +8,7 @@ const node = require('@neutrinojs/node');
const glob = require('glob');
const {
FLECKS_ROOT = process.cwd(),
FLECKS_CORE_ROOT = process.cwd(),
} = process.env;
module.exports = require('../src/bootstrap/fleck.neutrinorc');
@ -26,8 +26,8 @@ module.exports.use.push((neutrino) => {
// Tests.
module.exports.use.push((neutrino) => {
// Test entrypoint.
const testPaths = glob.sync(join(FLECKS_ROOT, 'test/*.js'));
testPaths.push(...glob.sync(join(FLECKS_ROOT, `test/platforms/server/*.js`)));
const testPaths = glob.sync(join(FLECKS_CORE_ROOT, 'test/*.js'));
testPaths.push(...glob.sync(join(FLECKS_CORE_ROOT, `test/platforms/server/*.js`)));
if (testPaths.length > 0) {
const testEntry = neutrino.config.entry('test').clear();
testPaths.forEach((path) => testEntry.add(path));

View File

@ -71,7 +71,7 @@ from the `build` directory. The resolution order is determined by a few variable
an overridden `server.neutrinorc.js` when building, however `general` is set to `.neutrinorc.js`,
so it will also accept overrides of that more general configuration file.
- `root` specifies an alternative location to search. Defaults to `FLECKS_ROOT`.
- `root` specifies an alternative location to search. Defaults to `FLECKS_CORE_ROOT`.
- `fleck` specifies the fleck owning the configuration. `@flecks/core` owns `babel.config.js`,
`@flecks/server` owns `server.neutrinorc.js`, etc. This only really matters if you are writing a
@ -90,7 +90,7 @@ We would then expect flecks to search using the following resolution order:
- `/foo/bar/baz/build/server.neutrinorc.js`
- `/foo/bar/baz/build/.neutrinorc.js`
- `${FLECKS_ROOT}/build/server.neutrinorc.js`
- `${FLECKS_ROOT}/build/.neutrinorc.js`
- `${FLECKS_CORE_ROOT}/build/server.neutrinorc.js`
- `${FLECKS_CORE_ROOT}/build/.neutrinorc.js`
- `@flecks/server/build/server.neutrinorc.js`
- `@flecks/server/build/.neutrinorc.js`

View File

@ -8,7 +8,7 @@ const {
const R = require('./require');
const {
FLECKS_ROOT = process.cwd(),
FLECKS_CORE_ROOT = process.cwd(),
} = process.env;
const resolver = (source) => (path) => {
@ -36,7 +36,7 @@ module.exports = () => (neutrino) => {
neutrino.config.entryPoints.delete('index');
// Alias this package.
neutrino.config.resolve.alias
.set(name, join(FLECKS_ROOT, 'src'));
.set(name, join(FLECKS_CORE_ROOT, 'src'));
// Calculate entry points from `files`.
files
.filter(resolver(source))

View File

@ -4,13 +4,13 @@ const autoentry = require('./autoentry');
const fleck = require('./fleck');
const {
FLECKS_ROOT = process.cwd(),
FLECKS_CORE_ROOT = process.cwd(),
} = process.env;
module.exports = {
options: {
output: 'dist',
root: FLECKS_ROOT,
root: FLECKS_CORE_ROOT,
},
use: [
copy({

View File

@ -5,11 +5,11 @@ const {targetNeutrino} = require('../server/commands');
const {default: Flecks} = require('../server/flecks');
const {
FLECKS_BUILD_TARGET = 'fleck',
FLECKS_CORE_BUILD_TARGET = 'fleck',
} = process.env;
const flecks = Flecks.bootstrap();
const config = R(process.env[targetNeutrino(FLECKS_BUILD_TARGET)]);
flecks.invokeFlat('@flecks/core/build', FLECKS_BUILD_TARGET, config);
const config = R(process.env[targetNeutrino(FLECKS_CORE_BUILD_TARGET)]);
flecks.invokeFlat('@flecks/core/build', FLECKS_CORE_BUILD_TARGET, config);
module.exports = neutrino(config).eslintrc();

View File

@ -21,10 +21,10 @@ import Flecks from '../server/flecks';
const debug = D('@flecks/core/build/webpack.config.js');
const {
FLECKS_BUILD_LIST = '',
FLECKS_CORE_BUILD_LIST = '',
} = process.env;
const buildList = FLECKS_BUILD_LIST
const buildList = FLECKS_CORE_BUILD_LIST
.split(',')
.map((name) => name.trim())
.filter((e) => e);

View File

@ -7,13 +7,13 @@ import D from 'debug';
import Flecks from './server/flecks';
const {
FLECKS_ROOT = process.cwd(),
FLECKS_CORE_ROOT = process.cwd(),
} = process.env;
const debug = D('@flecks/core/cli');
// Guarantee local node_modules path.
const defaultNodeModules = resolve(join(FLECKS_ROOT, 'node_modules'));
const defaultNodeModules = resolve(join(FLECKS_CORE_ROOT, 'node_modules'));
const nodePathSeparator = '/' === sep ? ':' : ';';
let updatedNodePath;
if (!process.env.NODE_PATH) {

View File

@ -7,11 +7,11 @@ import flatten from 'lodash.flatten';
import rimraf from 'rimraf';
const {
FLECKS_ROOT = process.cwd(),
FLECKS_CORE_ROOT = process.cwd(),
} = process.env;
const debug = D('@flecks/core/commands');
const flecksRoot = normalize(FLECKS_ROOT);
const flecksRoot = normalize(FLECKS_CORE_ROOT);
export const spawnWith = (cmd, localEnv, spawnArgs) => {
debug('spawning:\n%s %s\nwith local environment: %O', cmd, spawnArgs.join(' '), localEnv);
@ -98,8 +98,8 @@ export default (program, flecks) => {
const webpackConfig = flecks.localConfig('webpack.config.js', '@flecks/core');
const localEnv = {
...targetNeutrinos(flecks),
...(target ? {FLECKS_BUILD_LIST: target} : {}),
...(hot ? {FLECKS_HOT: 1} : {}),
...(target ? {FLECKS_CORE_BUILD_LIST: target} : {}),
...(hot ? {FLECKS_ENV_FLECKS_SERVER_hot: 'true'} : {}),
};
const spawnArgs = [
'--colors',
@ -124,7 +124,7 @@ export default (program, flecks) => {
// eslint-disable-next-line no-continue
continue;
}
process.env.FLECKS_BUILD_TARGET = target;
process.env.FLECKS_CORE_BUILD_TARGET = target;
const spawnArgs = [
'--config', flecks.localConfig(
`${target}.eslintrc.js`,
@ -136,7 +136,7 @@ export default (program, flecks) => {
'.',
];
const localEnv = {
FLECKS_BUILD_TARGET: target,
FLECKS_CORE_BUILD_TARGET: target,
...targetNeutrinos(flecks),
};
promises.push(new Promise((resolve, reject) => {

View File

@ -19,7 +19,7 @@ import R from '../bootstrap/require';
import Flecks from '../flecks';
const {
FLECKS_ROOT = process.cwd(),
FLECKS_CORE_ROOT = process.cwd(),
} = process.env;
const debug = D('@flecks/core/flecks/server');
@ -106,11 +106,11 @@ export default class ServerFlecks extends Flecks {
static bootstrap(
{
platforms = ['server'],
root = FLECKS_ROOT,
root = FLECKS_CORE_ROOT,
without = [],
} = {},
) {
const resolvedRoot = resolve(FLECKS_ROOT, root);
const resolvedRoot = resolve(FLECKS_CORE_ROOT, root);
let initial;
let configType;
try {
@ -374,7 +374,7 @@ export default class ServerFlecks extends Flecks {
return this.constructor.localConfig(this.resolver, path, fleck, options);
}
static localConfig(resolver, path, fleck, {general = path, root = FLECKS_ROOT} = {}) {
static localConfig(resolver, path, fleck, {general = path, root = FLECKS_CORE_ROOT} = {}) {
let configFile;
try {
const localConfig = join(root, 'build', path);
@ -389,13 +389,13 @@ export default class ServerFlecks extends Flecks {
}
catch (error) {
try {
const localConfig = join(FLECKS_ROOT, 'build', path);
const localConfig = join(FLECKS_CORE_ROOT, 'build', path);
statSync(localConfig);
configFile = localConfig;
}
catch (error) {
try {
const localConfig = join(FLECKS_ROOT, 'build', general);
const localConfig = join(FLECKS_CORE_ROOT, 'build', general);
statSync(localConfig);
configFile = localConfig;
}

View File

@ -3,7 +3,7 @@ import {expect} from 'chai';
// eslint-disable-next-line import/no-unresolved
import {Flecks} from '@flecks/core/server';
it('bootstraps FLECKS_ROOT by default', () => {
it('bootstraps FLECKS_CORE_ROOT by default', () => {
const flecks = Flecks.bootstrap();
expect(flecks.fleck('@flecks/core')).to.not.equal(undefined);
});

View File

@ -1,2 +1,3 @@
'@flecks/core': {}
'@flecks/server': {}
'@flecks/server':
start: true

View File

@ -2,7 +2,7 @@
"private": true,
"scripts": {
"build": "flecks build",
"dev": "FLECKS_START_SERVER=1 npm run -- build -h"
"dev": "npm run -- build -h"
},
"dependencies": {
"@flecks/core": "^1.0.0",

View File

@ -10,10 +10,10 @@ import {copySync, moveSync} from 'fs-extra';
import validate from 'validate-npm-package-name';
const {
FLECKS_ROOT = process.cwd(),
FLECKS_CORE_ROOT = process.cwd(),
} = process.env;
const cwd = normalize(FLECKS_ROOT);
const cwd = normalize(FLECKS_CORE_ROOT);
const forwardProcessCode = (fn) => async (...args) => {
process.exitCode = await fn(args.slice(0, -2));

View File

@ -2,16 +2,38 @@ import {ByType} from '@flecks/core';
import D from 'debug';
import Sequelize from 'sequelize';
import environment from './environment';
const debug = D('@flecks/db/server/connection');
export async function createDatabaseConnection(flecks) {
const env = environment();
debug('environment: %O', {...env, ...(env.password ? {password: '*** REDACTED ***'} : {})});
let config = {};
const {
dialect,
username,
password,
host,
port,
database,
} = flecks.get('@flecks/db/server');
if ('sqlite' === dialect) {
config = {
dialect: 'sqlite',
storage: database,
};
}
else {
config = {
dialect,
username,
password,
host,
port,
database,
};
}
debug('config: %O', {...config, ...(config.password ? {password: '*** REDACTED ***'} : {})});
const sequelize = new Sequelize({
logging: false,
...env,
...config,
});
const Models = flecks.get('$flecks/db.models')[ByType];
Object.values(Models)

View File

@ -1,13 +1,11 @@
import environment from './environment';
export default () => {
export default (flecks) => {
const {
dialect,
username,
password,
port,
database,
} = environment();
} = flecks.get('@flecks/db/server');
let args = [];
let image;
let mount;

View File

@ -1,25 +0,0 @@
const {
SEQUELIZE_DIALECT = 'sqlite',
SEQUELIZE_USER = 'user',
SEQUELIZE_PASSWORD = 'Set_The_SEQUELIZE_PASSWORD_Environment_Variable',
SEQUELIZE_HOST = 'localhost',
SEQUELIZE_PORT,
SEQUELIZE_DATABASE = ':memory:',
} = process.env;
export default () => {
if ('sqlite' === SEQUELIZE_DIALECT) {
return ({
dialect: 'sqlite',
storage: SEQUELIZE_DATABASE,
});
}
return ({
dialect: SEQUELIZE_DIALECT,
username: SEQUELIZE_USER,
password: SEQUELIZE_PASSWORD,
host: SEQUELIZE_HOST,
port: SEQUELIZE_PORT,
database: SEQUELIZE_DATABASE,
});
};

View File

@ -12,7 +12,13 @@ export {createDatabaseConnection};
export default {
[Hooks]: {
'@flecks/core/config': () => ({
dialect: 'sqlite',
username: undefined,
password: undefined,
host: undefined,
'models.decorate': ['...'],
port: undefined,
database: ':memory:',
}),
'@flecks/core/starting': (flecks) => {
flecks.set('$flecks/db.models', flecks.gather(

View File

@ -7,7 +7,7 @@ const D = require('debug');
const glob = require('glob');
const {
FLECKS_ROOT = process.cwd(),
FLECKS_CORE_ROOT = process.cwd(),
} = process.env;
const debug = D('@flecks/fleck/fleck.neutrino.js');
@ -47,9 +47,9 @@ config.use.push((neutrino) => {
config.use.push((neutrino) => {
// Test entrypoint.
const testPaths = glob.sync(join(FLECKS_ROOT, 'test/*.js'));
const testPaths = glob.sync(join(FLECKS_CORE_ROOT, 'test/*.js'));
for (let i = 0; i < flecks.platforms.length; ++i) {
testPaths.push(...glob.sync(join(FLECKS_ROOT, `test/platforms/${flecks.platforms[i]}/*.js`)));
testPaths.push(...glob.sync(join(FLECKS_CORE_ROOT, `test/platforms/${flecks.platforms[i]}/*.js`)));
}
if (testPaths.length > 0) {
const testEntry = neutrino.config.entry('test').clear();

View File

@ -13,7 +13,7 @@ import {
const debug = D('@flecks/core/commands');
const {
FLECKS_ROOT = process.cwd(),
FLECKS_CORE_ROOT = process.cwd(),
} = process.env;
export default (program, flecks) => {
@ -29,13 +29,13 @@ export default (program, flecks) => {
const {
watch,
} = opts;
const testPaths = glob.sync(join(FLECKS_ROOT, 'test/*.js'));
const testPaths = glob.sync(join(FLECKS_CORE_ROOT, 'test/*.js'));
if (0 === testPaths.length) {
// eslint-disable-next-line no-console
console.log('No fleck tests found.');
return 0;
}
const testLocation = join(FLECKS_ROOT, 'dist', 'test.js');
const testLocation = join(FLECKS_CORE_ROOT, 'dist', 'test.js');
if (watch) {
await unlink(testLocation);
}

View File

@ -1,7 +1,7 @@
import {createClient} from 'redis';
import {RateLimiterRedis} from 'rate-limiter-flexible';
export default async (options) => {
export default async (flecks, options) => {
const storeClient = createClient();
// @todo node-redis@4
// await storeClient.connect();

View File

@ -55,10 +55,13 @@ export default {
'@flecks/server/up': async (flecks) => {
if (flecks.fleck('@flecks/http/server')) {
const {http} = flecks.get('@flecks/governor/server');
const limiter = await createLimiter({
keyPrefix: '@flecks/governor.http.request.route',
...http,
});
const limiter = await createLimiter(
flecks,
{
keyPrefix: '@flecks/governor.http.request.route',
...http,
},
);
flecks.set('$flecks/governor.http.limiter', limiter);
}
if (flecks.fleck('@flecks/socket/server')) {
@ -70,17 +73,23 @@ export default {
.map(async ([name, Packet]) => (
[
name,
await createLimiter({keyPrefix: `@flecks/governor.packet.${name}`, ...Packet.limit}),
await createLimiter(
flecks,
{keyPrefix: `@flecks/governor.packet.${name}`, ...Packet.limit},
),
]
)),
),
);
flecks.set('$flecks/governor.packet.limiters', limiters);
const {socket} = flecks.get('@flecks/governor/server');
const limiter = await createLimiter({
keyPrefix: '@flecks/governor.socket.request.socket',
...socket,
});
const limiter = await createLimiter(
flecks,
{
keyPrefix: '@flecks/governor.socket.request.socket',
...socket,
},
);
flecks.set('$flecks/governor.socket.limiter', limiter);
}
},

View File

@ -1,10 +1,8 @@
const env = require('../environment');
module.exports = () => (neutrino) => {
module.exports = (flecks) => (neutrino) => {
if ('production' === neutrino.config.get('mode')) {
return;
}
const {devHost, devPort, devPublic} = env();
const {devHost, devPort, devPublic} = flecks.get('@flecks/http/server');
neutrino.config.devServer
.hot(false)
.host(devHost)

View File

@ -9,7 +9,7 @@ const runtime = require('./runtime');
const targets = require('./targets');
const {
FLECKS_ROOT = process.cwd(),
FLECKS_CORE_ROOT = process.cwd(),
} = process.env;
const debug = D('@flecks/http/http.neutrino.js');
@ -22,14 +22,14 @@ debug('bootstrapped');
const config = {
options: {
output: 'dist',
root: FLECKS_ROOT,
root: FLECKS_CORE_ROOT,
},
use: [
({config}) => {
config
.plugin('environment')
.use(EnvironmentPlugin, [{
FLECKS_BUILD_TARGET: 'client',
FLECKS_CORE_BUILD_TARGET: 'client',
}]);
},
targets(flecks),
@ -63,7 +63,7 @@ else {
}));
}
// Configure dev server.
config.use.push(devServer());
config.use.push(devServer(flecks));
// Build the client runtime.
config.use.push(runtime(flecks));
// Output configuration.

View File

@ -5,15 +5,14 @@ const {realpathSync} = require('fs');
const {require: R} = require('@flecks/core/server');
const {
FLECKS_HTTP_OUTPUT = 'http',
FLECKS_ROOT = process.cwd(),
FLECKS_CORE_ROOT = process.cwd(),
} = process.env;
module.exports = (flecks) => (neutrino) => {
const {options} = neutrino;
const {output: originalOutput} = options;
neutrino.config.resolve.modules.merge([
join(FLECKS_ROOT, 'node_modules'),
join(FLECKS_CORE_ROOT, 'node_modules'),
'node_modules',
]);
options.root = realpathSync(dirname(R.resolve(join(flecks.resolve('@flecks/http'), 'entry.js'))));
@ -23,5 +22,5 @@ module.exports = (flecks) => (neutrino) => {
entry: './client/tests',
title: 'Testbed',
};
options.output = join(originalOutput, FLECKS_HTTP_OUTPUT);
options.output = join(originalOutput, flecks.get('@flecks/http/server.output'));
};

View File

@ -1,15 +0,0 @@
const {
HTTP_DEV_HOST = 'localhost',
HTTP_DEV_PORT = 32341,
HTTP_DEV_PUBLIC,
HTTP_HOST = '0.0.0.0',
HTTP_PORT = 32340,
} = process.env;
module.exports = () => ({
devHost: HTTP_DEV_HOST,
devPort: HTTP_DEV_PORT,
devPublic: HTTP_DEV_PUBLIC,
host: HTTP_HOST,
port: HTTP_PORT,
});

View File

@ -8,11 +8,8 @@ import express from 'express';
import httpProxy from 'http-proxy';
import flatten from 'lodash.flatten';
import env from './environment';
const {
FLECKS_HTTP_OUTPUT = 'http',
FLECKS_ROOT = process.cwd(),
FLECKS_CORE_ROOT = process.cwd(),
NODE_ENV,
} = process.env;
@ -28,8 +25,9 @@ export const createHttpServer = async (flecks) => {
devHost,
devPort,
host,
output,
port,
} = env();
} = flecks.get('@flecks/http/server');
const app = express();
app.set('trust proxy', trust);
const httpServer = createServer(app);
@ -90,18 +88,18 @@ export const createHttpServer = async (flecks) => {
}
else {
// Serve the document root, sans index.
app.use(express.static(join(FLECKS_ROOT, 'dist', FLECKS_HTTP_OUTPUT), {index: false}));
app.use(express.static(join(FLECKS_CORE_ROOT, 'dist', output), {index: false}));
// Tests bypass middleware and stream processing.
app.get('/tests.html', (req, res) => {
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
const stream = createReadStream(join(FLECKS_ROOT, 'dist', FLECKS_HTTP_OUTPUT, 'tests.html'));
const stream = createReadStream(join(FLECKS_CORE_ROOT, 'dist', output, 'tests.html'));
stream.pipe(res);
});
// Fallback to serving HTML.
app.get('*', routeMiddleware, async (req, res) => {
if (req.accepts('text/html')) {
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
const stream = createReadStream(join(FLECKS_ROOT, 'dist', FLECKS_HTTP_OUTPUT, 'index.html'));
const stream = createReadStream(join(FLECKS_CORE_ROOT, 'dist', output, 'index.html'));
deliverHtmlStream(stream, flecks, req, res);
}
else {

View File

@ -20,7 +20,7 @@ export default {
}
// Otherwise, spawn `webpack-dev-server` (WDS).
const localEnv = {
FLECKS_BUILD_LIST: 'http',
FLECKS_CORE_BUILD_LIST: 'http',
};
const spawnArgs = [
'--mode', 'development',
@ -33,6 +33,12 @@ export default {
delete neutrinoConfigs.http;
},
'@flecks/core/config': () => ({
devHost: 'localhost',
devPort: 32341,
devPublic: undefined,
host: '0.0.0.0',
output: 'http',
port: 32340,
'stream.html': ['...'],
'request.route': [],
'request.socket': [],

View File

@ -1,11 +1,7 @@
const {
REDIS_PORT = 6379,
} = process.env;
export default () => ({
export default (flecks) => ({
redis: {
image: 'redis',
mount: '/data',
ports: {[REDIS_PORT]: 6379},
ports: {[flecks.get('@flecks/redis/server.port')]: 6379},
},
});

View File

@ -1,13 +1,12 @@
import {createClient} from 'redis';
const {
REDIS_HOST = 'localhost',
REDIS_PORT = 6379,
} = process.env;
export default (opts = {}) => (
createClient({
url: `redis://${opts.host || REDIS_HOST}:${opts.port || REDIS_PORT}`,
export default (flecks, opts = {}) => {
const {
host,
port,
} = flecks.get('@flecks/redis/server');
return createClient({
url: `redis://${host}:${port}`,
...opts,
})
);
});
};

View File

@ -29,9 +29,13 @@ export const keys = (client, pattern) => safeKeys(client, pattern, 0);
export default {
[Hooks]: {
'@flecks/core/config': () => ({
host: 'localhost',
port: 6379,
}),
'@flecks/docker/containers': containers,
'@flecks/repl/context': () => ({
redisClient: createClient(),
'@flecks/repl/context': (flecks) => ({
redisClient: createClient(flecks),
}),
},
};

View File

@ -12,16 +12,16 @@ const RedisStore = ConnectRedis(session);
export default {
[Hooks]: {
'@flecks/user/session': async () => {
const client = createClient({legacyMode: true});
'@flecks/user/session': async (flecks) => {
const client = createClient(flecks, {legacyMode: true});
await client.connect();
return {
store: new RedisStore({client}),
};
},
'@flecks/socket/server': async () => {
const pubClient = createClient();
const subClient = createClient();
'@flecks/socket/server': async (flecks) => {
const pubClient = createClient(flecks);
const subClient = createClient(flecks);
await Promise.all([pubClient.connect(), subClient.connect()]);
debug('creating adapter');
return {

View File

@ -3,6 +3,10 @@ import {Hooks} from '@flecks/core';
export default {
[Hooks]: {
'@flecks/core/config': () => ({
hot: false,
inspect: false,
profile: false,
start: false,
up: ['...'],
}),
},

View File

@ -8,7 +8,7 @@ module.exports = (flecks) => (neutrino) => {
// Inject flecks configuration.
const paths = Object.keys(resolver);
const source = [
"process.env.FLECKS_BUILD_TARGET = 'server';",
"process.env.FLECKS_CORE_BUILD_TARGET = 'server';",
'module.exports = (async () => ({',
` config: ${JSON.stringify(config)},`,
' flecks: Object.fromEntries(await Promise.all([',

View File

@ -9,11 +9,7 @@ const D = require('debug');
const runtime = require('./runtime');
const {
FLECKS_HOT = false,
FLECKS_INSPECT = false,
FLECKS_PROFILE = false,
FLECKS_ROOT = process.cwd(),
FLECKS_START_SERVER = false,
FLECKS_CORE_ROOT = process.cwd(),
} = process.env;
const debug = D('@flecks/server/server.neutrino.js');
@ -22,15 +18,22 @@ debug('bootstrapping flecks...');
const flecks = Flecks.bootstrap();
debug('bootstrapped');
const {
hot,
inspect,
profile,
start: isStarting,
} = flecks.get('@flecks/server');
const entry = (neutrino) => {
const entries = neutrino.config.entry('index');
entries.delete(join(FLECKS_ROOT, 'src', 'index'));
entries.delete(join(FLECKS_CORE_ROOT, 'src', 'index'));
entries.add('@flecks/server/entry');
};
// Augment the application-starting configuration.
const start = (neutrino) => {
if (FLECKS_START_SERVER) {
if (isStarting) {
neutrino.use(startServer({name: 'index.js'}));
}
if (!neutrino.config.plugins.has('start-server')) {
@ -42,13 +45,13 @@ const start = (neutrino) => {
const options = args[0];
options.keyboard = false;
// HMR.
options.signal = true;
options.signal = !!hot;
// Debugging.
if (FLECKS_INSPECT) {
if (inspect) {
options.nodeArgs.push('--inspect');
}
// Profiling.
if (FLECKS_PROFILE) {
if (profile) {
options.nodeArgs.push('--prof');
}
// Bail hard on unhandled rejections and report.
@ -66,7 +69,7 @@ const compiler = flecks.invokeFleck(
const config = {
options: {
output: 'dist',
root: FLECKS_ROOT,
root: FLECKS_CORE_ROOT,
},
use: [
entry,
@ -84,7 +87,7 @@ else {
});
config.use.unshift(node({
clean: false,
hot: FLECKS_HOT,
hot,
}));
}
// Stub out non-server-friendly modules on the server.
@ -123,7 +126,7 @@ config.use.push(runtime(flecks));
// Give the resolver a helping hand.
config.use.push((neutrino) => {
neutrino.config.resolve.modules.merge([
join(FLECKS_ROOT, 'node_modules'),
join(FLECKS_CORE_ROOT, 'node_modules'),
'node_modules',
]);
});

View File

@ -1,5 +1,9 @@
import D from 'debug';
const {
NODE_ENV,
} = process.env;
const debug = D('@flecks/socket/acceptor');
export default (socket) => async (packet, fn) => {
@ -17,9 +21,6 @@ export default (socket) => async (packet, fn) => {
return;
}
debug('acceptor error: %O', error);
const {
NODE_ENV,
} = process.env;
if (error instanceof Error) {
fn({
code: error.code || 500,

View File

@ -5,12 +5,13 @@ import expressSession from 'express-session';
const debug = D('@flecks/user/session');
const {
FLECKS_USER_COOKIE_SECRET = 'UNSAFE_DEV_COOKIE',
} = process.env;
export default {
[Hooks]: {
'@flecks/core/config': () => ({
cookieSecret: (
'Set the FLECKS_ENV_FLECKS_USER_SESSION_SERVER_cookieSecret environment variable!'
),
}),
'@flecks/http/server/request.route': (flecks) => {
const urle = express.urlencoded({extended: true});
return (req, res, next) => {
@ -37,7 +38,7 @@ export default {
resave: false,
sameSite: true,
saveUninitialized: false,
secret: FLECKS_USER_COOKIE_SECRET,
secret: flecks.get('@flecks/user/session/server.cookieSecret'),
...await flecks.invokeReduceAsync('@flecks/user/session'),
}));
},