refactor: environment
This commit is contained in:
parent
8ed96484b9
commit
d6d7260799
|
@ -8,7 +8,7 @@ const node = require('@neutrinojs/node');
|
||||||
const glob = require('glob');
|
const glob = require('glob');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
FLECKS_ROOT = process.cwd(),
|
FLECKS_CORE_ROOT = process.cwd(),
|
||||||
} = process.env;
|
} = process.env;
|
||||||
|
|
||||||
module.exports = require('../src/bootstrap/fleck.neutrinorc');
|
module.exports = require('../src/bootstrap/fleck.neutrinorc');
|
||||||
|
@ -26,8 +26,8 @@ module.exports.use.push((neutrino) => {
|
||||||
// Tests.
|
// Tests.
|
||||||
module.exports.use.push((neutrino) => {
|
module.exports.use.push((neutrino) => {
|
||||||
// Test entrypoint.
|
// Test entrypoint.
|
||||||
const testPaths = glob.sync(join(FLECKS_ROOT, 'test/*.js'));
|
const testPaths = glob.sync(join(FLECKS_CORE_ROOT, 'test/*.js'));
|
||||||
testPaths.push(...glob.sync(join(FLECKS_ROOT, `test/platforms/server/*.js`)));
|
testPaths.push(...glob.sync(join(FLECKS_CORE_ROOT, `test/platforms/server/*.js`)));
|
||||||
if (testPaths.length > 0) {
|
if (testPaths.length > 0) {
|
||||||
const testEntry = neutrino.config.entry('test').clear();
|
const testEntry = neutrino.config.entry('test').clear();
|
||||||
testPaths.forEach((path) => testEntry.add(path));
|
testPaths.forEach((path) => testEntry.add(path));
|
||||||
|
|
|
@ -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`,
|
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.
|
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`,
|
- `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
|
`@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/server.neutrinorc.js`
|
||||||
- `/foo/bar/baz/build/.neutrinorc.js`
|
- `/foo/bar/baz/build/.neutrinorc.js`
|
||||||
- `${FLECKS_ROOT}/build/server.neutrinorc.js`
|
- `${FLECKS_CORE_ROOT}/build/server.neutrinorc.js`
|
||||||
- `${FLECKS_ROOT}/build/.neutrinorc.js`
|
- `${FLECKS_CORE_ROOT}/build/.neutrinorc.js`
|
||||||
- `@flecks/server/build/server.neutrinorc.js`
|
- `@flecks/server/build/server.neutrinorc.js`
|
||||||
- `@flecks/server/build/.neutrinorc.js`
|
- `@flecks/server/build/.neutrinorc.js`
|
||||||
|
|
|
@ -8,7 +8,7 @@ const {
|
||||||
const R = require('./require');
|
const R = require('./require');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
FLECKS_ROOT = process.cwd(),
|
FLECKS_CORE_ROOT = process.cwd(),
|
||||||
} = process.env;
|
} = process.env;
|
||||||
|
|
||||||
const resolver = (source) => (path) => {
|
const resolver = (source) => (path) => {
|
||||||
|
@ -36,7 +36,7 @@ module.exports = () => (neutrino) => {
|
||||||
neutrino.config.entryPoints.delete('index');
|
neutrino.config.entryPoints.delete('index');
|
||||||
// Alias this package.
|
// Alias this package.
|
||||||
neutrino.config.resolve.alias
|
neutrino.config.resolve.alias
|
||||||
.set(name, join(FLECKS_ROOT, 'src'));
|
.set(name, join(FLECKS_CORE_ROOT, 'src'));
|
||||||
// Calculate entry points from `files`.
|
// Calculate entry points from `files`.
|
||||||
files
|
files
|
||||||
.filter(resolver(source))
|
.filter(resolver(source))
|
||||||
|
|
|
@ -4,13 +4,13 @@ const autoentry = require('./autoentry');
|
||||||
const fleck = require('./fleck');
|
const fleck = require('./fleck');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
FLECKS_ROOT = process.cwd(),
|
FLECKS_CORE_ROOT = process.cwd(),
|
||||||
} = process.env;
|
} = process.env;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
options: {
|
options: {
|
||||||
output: 'dist',
|
output: 'dist',
|
||||||
root: FLECKS_ROOT,
|
root: FLECKS_CORE_ROOT,
|
||||||
},
|
},
|
||||||
use: [
|
use: [
|
||||||
copy({
|
copy({
|
||||||
|
|
|
@ -5,11 +5,11 @@ const {targetNeutrino} = require('../server/commands');
|
||||||
const {default: Flecks} = require('../server/flecks');
|
const {default: Flecks} = require('../server/flecks');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
FLECKS_BUILD_TARGET = 'fleck',
|
FLECKS_CORE_BUILD_TARGET = 'fleck',
|
||||||
} = process.env;
|
} = process.env;
|
||||||
|
|
||||||
const flecks = Flecks.bootstrap();
|
const flecks = Flecks.bootstrap();
|
||||||
|
|
||||||
const config = R(process.env[targetNeutrino(FLECKS_BUILD_TARGET)]);
|
const config = R(process.env[targetNeutrino(FLECKS_CORE_BUILD_TARGET)]);
|
||||||
flecks.invokeFlat('@flecks/core/build', FLECKS_BUILD_TARGET, config);
|
flecks.invokeFlat('@flecks/core/build', FLECKS_CORE_BUILD_TARGET, config);
|
||||||
module.exports = neutrino(config).eslintrc();
|
module.exports = neutrino(config).eslintrc();
|
||||||
|
|
|
@ -21,10 +21,10 @@ import Flecks from '../server/flecks';
|
||||||
const debug = D('@flecks/core/build/webpack.config.js');
|
const debug = D('@flecks/core/build/webpack.config.js');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
FLECKS_BUILD_LIST = '',
|
FLECKS_CORE_BUILD_LIST = '',
|
||||||
} = process.env;
|
} = process.env;
|
||||||
|
|
||||||
const buildList = FLECKS_BUILD_LIST
|
const buildList = FLECKS_CORE_BUILD_LIST
|
||||||
.split(',')
|
.split(',')
|
||||||
.map((name) => name.trim())
|
.map((name) => name.trim())
|
||||||
.filter((e) => e);
|
.filter((e) => e);
|
||||||
|
|
|
@ -7,13 +7,13 @@ import D from 'debug';
|
||||||
import Flecks from './server/flecks';
|
import Flecks from './server/flecks';
|
||||||
|
|
||||||
const {
|
const {
|
||||||
FLECKS_ROOT = process.cwd(),
|
FLECKS_CORE_ROOT = process.cwd(),
|
||||||
} = process.env;
|
} = process.env;
|
||||||
|
|
||||||
const debug = D('@flecks/core/cli');
|
const debug = D('@flecks/core/cli');
|
||||||
|
|
||||||
// Guarantee local node_modules path.
|
// 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 ? ':' : ';';
|
const nodePathSeparator = '/' === sep ? ':' : ';';
|
||||||
let updatedNodePath;
|
let updatedNodePath;
|
||||||
if (!process.env.NODE_PATH) {
|
if (!process.env.NODE_PATH) {
|
||||||
|
|
|
@ -7,11 +7,11 @@ import flatten from 'lodash.flatten';
|
||||||
import rimraf from 'rimraf';
|
import rimraf from 'rimraf';
|
||||||
|
|
||||||
const {
|
const {
|
||||||
FLECKS_ROOT = process.cwd(),
|
FLECKS_CORE_ROOT = process.cwd(),
|
||||||
} = process.env;
|
} = process.env;
|
||||||
|
|
||||||
const debug = D('@flecks/core/commands');
|
const debug = D('@flecks/core/commands');
|
||||||
const flecksRoot = normalize(FLECKS_ROOT);
|
const flecksRoot = normalize(FLECKS_CORE_ROOT);
|
||||||
|
|
||||||
export const spawnWith = (cmd, localEnv, spawnArgs) => {
|
export const spawnWith = (cmd, localEnv, spawnArgs) => {
|
||||||
debug('spawning:\n%s %s\nwith local environment: %O', cmd, spawnArgs.join(' '), localEnv);
|
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 webpackConfig = flecks.localConfig('webpack.config.js', '@flecks/core');
|
||||||
const localEnv = {
|
const localEnv = {
|
||||||
...targetNeutrinos(flecks),
|
...targetNeutrinos(flecks),
|
||||||
...(target ? {FLECKS_BUILD_LIST: target} : {}),
|
...(target ? {FLECKS_CORE_BUILD_LIST: target} : {}),
|
||||||
...(hot ? {FLECKS_HOT: 1} : {}),
|
...(hot ? {FLECKS_ENV_FLECKS_SERVER_hot: 'true'} : {}),
|
||||||
};
|
};
|
||||||
const spawnArgs = [
|
const spawnArgs = [
|
||||||
'--colors',
|
'--colors',
|
||||||
|
@ -124,7 +124,7 @@ export default (program, flecks) => {
|
||||||
// eslint-disable-next-line no-continue
|
// eslint-disable-next-line no-continue
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
process.env.FLECKS_BUILD_TARGET = target;
|
process.env.FLECKS_CORE_BUILD_TARGET = target;
|
||||||
const spawnArgs = [
|
const spawnArgs = [
|
||||||
'--config', flecks.localConfig(
|
'--config', flecks.localConfig(
|
||||||
`${target}.eslintrc.js`,
|
`${target}.eslintrc.js`,
|
||||||
|
@ -136,7 +136,7 @@ export default (program, flecks) => {
|
||||||
'.',
|
'.',
|
||||||
];
|
];
|
||||||
const localEnv = {
|
const localEnv = {
|
||||||
FLECKS_BUILD_TARGET: target,
|
FLECKS_CORE_BUILD_TARGET: target,
|
||||||
...targetNeutrinos(flecks),
|
...targetNeutrinos(flecks),
|
||||||
};
|
};
|
||||||
promises.push(new Promise((resolve, reject) => {
|
promises.push(new Promise((resolve, reject) => {
|
||||||
|
|
|
@ -19,7 +19,7 @@ import R from '../bootstrap/require';
|
||||||
import Flecks from '../flecks';
|
import Flecks from '../flecks';
|
||||||
|
|
||||||
const {
|
const {
|
||||||
FLECKS_ROOT = process.cwd(),
|
FLECKS_CORE_ROOT = process.cwd(),
|
||||||
} = process.env;
|
} = process.env;
|
||||||
|
|
||||||
const debug = D('@flecks/core/flecks/server');
|
const debug = D('@flecks/core/flecks/server');
|
||||||
|
@ -106,11 +106,11 @@ export default class ServerFlecks extends Flecks {
|
||||||
static bootstrap(
|
static bootstrap(
|
||||||
{
|
{
|
||||||
platforms = ['server'],
|
platforms = ['server'],
|
||||||
root = FLECKS_ROOT,
|
root = FLECKS_CORE_ROOT,
|
||||||
without = [],
|
without = [],
|
||||||
} = {},
|
} = {},
|
||||||
) {
|
) {
|
||||||
const resolvedRoot = resolve(FLECKS_ROOT, root);
|
const resolvedRoot = resolve(FLECKS_CORE_ROOT, root);
|
||||||
let initial;
|
let initial;
|
||||||
let configType;
|
let configType;
|
||||||
try {
|
try {
|
||||||
|
@ -374,7 +374,7 @@ export default class ServerFlecks extends Flecks {
|
||||||
return this.constructor.localConfig(this.resolver, path, fleck, options);
|
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;
|
let configFile;
|
||||||
try {
|
try {
|
||||||
const localConfig = join(root, 'build', path);
|
const localConfig = join(root, 'build', path);
|
||||||
|
@ -389,13 +389,13 @@ export default class ServerFlecks extends Flecks {
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
try {
|
try {
|
||||||
const localConfig = join(FLECKS_ROOT, 'build', path);
|
const localConfig = join(FLECKS_CORE_ROOT, 'build', path);
|
||||||
statSync(localConfig);
|
statSync(localConfig);
|
||||||
configFile = localConfig;
|
configFile = localConfig;
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
try {
|
try {
|
||||||
const localConfig = join(FLECKS_ROOT, 'build', general);
|
const localConfig = join(FLECKS_CORE_ROOT, 'build', general);
|
||||||
statSync(localConfig);
|
statSync(localConfig);
|
||||||
configFile = localConfig;
|
configFile = localConfig;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import {expect} from 'chai';
|
||||||
// eslint-disable-next-line import/no-unresolved
|
// eslint-disable-next-line import/no-unresolved
|
||||||
import {Flecks} from '@flecks/core/server';
|
import {Flecks} from '@flecks/core/server';
|
||||||
|
|
||||||
it('bootstraps FLECKS_ROOT by default', () => {
|
it('bootstraps FLECKS_CORE_ROOT by default', () => {
|
||||||
const flecks = Flecks.bootstrap();
|
const flecks = Flecks.bootstrap();
|
||||||
expect(flecks.fleck('@flecks/core')).to.not.equal(undefined);
|
expect(flecks.fleck('@flecks/core')).to.not.equal(undefined);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
'@flecks/core': {}
|
'@flecks/core': {}
|
||||||
'@flecks/server': {}
|
'@flecks/server':
|
||||||
|
start: true
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "flecks build",
|
"build": "flecks build",
|
||||||
"dev": "FLECKS_START_SERVER=1 npm run -- build -h"
|
"dev": "npm run -- build -h"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@flecks/core": "^1.0.0",
|
"@flecks/core": "^1.0.0",
|
||||||
|
|
|
@ -10,10 +10,10 @@ import {copySync, moveSync} from 'fs-extra';
|
||||||
import validate from 'validate-npm-package-name';
|
import validate from 'validate-npm-package-name';
|
||||||
|
|
||||||
const {
|
const {
|
||||||
FLECKS_ROOT = process.cwd(),
|
FLECKS_CORE_ROOT = process.cwd(),
|
||||||
} = process.env;
|
} = process.env;
|
||||||
|
|
||||||
const cwd = normalize(FLECKS_ROOT);
|
const cwd = normalize(FLECKS_CORE_ROOT);
|
||||||
|
|
||||||
const forwardProcessCode = (fn) => async (...args) => {
|
const forwardProcessCode = (fn) => async (...args) => {
|
||||||
process.exitCode = await fn(args.slice(0, -2));
|
process.exitCode = await fn(args.slice(0, -2));
|
||||||
|
|
|
@ -2,16 +2,38 @@ import {ByType} from '@flecks/core';
|
||||||
import D from 'debug';
|
import D from 'debug';
|
||||||
import Sequelize from 'sequelize';
|
import Sequelize from 'sequelize';
|
||||||
|
|
||||||
import environment from './environment';
|
|
||||||
|
|
||||||
const debug = D('@flecks/db/server/connection');
|
const debug = D('@flecks/db/server/connection');
|
||||||
|
|
||||||
export async function createDatabaseConnection(flecks) {
|
export async function createDatabaseConnection(flecks) {
|
||||||
const env = environment();
|
let config = {};
|
||||||
debug('environment: %O', {...env, ...(env.password ? {password: '*** REDACTED ***'} : {})});
|
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({
|
const sequelize = new Sequelize({
|
||||||
logging: false,
|
logging: false,
|
||||||
...env,
|
...config,
|
||||||
});
|
});
|
||||||
const Models = flecks.get('$flecks/db.models')[ByType];
|
const Models = flecks.get('$flecks/db.models')[ByType];
|
||||||
Object.values(Models)
|
Object.values(Models)
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
import environment from './environment';
|
export default (flecks) => {
|
||||||
|
|
||||||
export default () => {
|
|
||||||
const {
|
const {
|
||||||
dialect,
|
dialect,
|
||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
port,
|
port,
|
||||||
database,
|
database,
|
||||||
} = environment();
|
} = flecks.get('@flecks/db/server');
|
||||||
let args = [];
|
let args = [];
|
||||||
let image;
|
let image;
|
||||||
let mount;
|
let mount;
|
||||||
|
|
|
@ -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,
|
|
||||||
});
|
|
||||||
};
|
|
|
@ -12,7 +12,13 @@ export {createDatabaseConnection};
|
||||||
export default {
|
export default {
|
||||||
[Hooks]: {
|
[Hooks]: {
|
||||||
'@flecks/core/config': () => ({
|
'@flecks/core/config': () => ({
|
||||||
|
dialect: 'sqlite',
|
||||||
|
username: undefined,
|
||||||
|
password: undefined,
|
||||||
|
host: undefined,
|
||||||
'models.decorate': ['...'],
|
'models.decorate': ['...'],
|
||||||
|
port: undefined,
|
||||||
|
database: ':memory:',
|
||||||
}),
|
}),
|
||||||
'@flecks/core/starting': (flecks) => {
|
'@flecks/core/starting': (flecks) => {
|
||||||
flecks.set('$flecks/db.models', flecks.gather(
|
flecks.set('$flecks/db.models', flecks.gather(
|
||||||
|
|
|
@ -7,7 +7,7 @@ const D = require('debug');
|
||||||
const glob = require('glob');
|
const glob = require('glob');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
FLECKS_ROOT = process.cwd(),
|
FLECKS_CORE_ROOT = process.cwd(),
|
||||||
} = process.env;
|
} = process.env;
|
||||||
|
|
||||||
const debug = D('@flecks/fleck/fleck.neutrino.js');
|
const debug = D('@flecks/fleck/fleck.neutrino.js');
|
||||||
|
@ -47,9 +47,9 @@ config.use.push((neutrino) => {
|
||||||
|
|
||||||
config.use.push((neutrino) => {
|
config.use.push((neutrino) => {
|
||||||
// Test entrypoint.
|
// 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) {
|
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) {
|
if (testPaths.length > 0) {
|
||||||
const testEntry = neutrino.config.entry('test').clear();
|
const testEntry = neutrino.config.entry('test').clear();
|
||||||
|
|
|
@ -13,7 +13,7 @@ import {
|
||||||
const debug = D('@flecks/core/commands');
|
const debug = D('@flecks/core/commands');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
FLECKS_ROOT = process.cwd(),
|
FLECKS_CORE_ROOT = process.cwd(),
|
||||||
} = process.env;
|
} = process.env;
|
||||||
|
|
||||||
export default (program, flecks) => {
|
export default (program, flecks) => {
|
||||||
|
@ -29,13 +29,13 @@ export default (program, flecks) => {
|
||||||
const {
|
const {
|
||||||
watch,
|
watch,
|
||||||
} = opts;
|
} = opts;
|
||||||
const testPaths = glob.sync(join(FLECKS_ROOT, 'test/*.js'));
|
const testPaths = glob.sync(join(FLECKS_CORE_ROOT, 'test/*.js'));
|
||||||
if (0 === testPaths.length) {
|
if (0 === testPaths.length) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log('No fleck tests found.');
|
console.log('No fleck tests found.');
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
const testLocation = join(FLECKS_ROOT, 'dist', 'test.js');
|
const testLocation = join(FLECKS_CORE_ROOT, 'dist', 'test.js');
|
||||||
if (watch) {
|
if (watch) {
|
||||||
await unlink(testLocation);
|
await unlink(testLocation);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import {createClient} from 'redis';
|
import {createClient} from 'redis';
|
||||||
import {RateLimiterRedis} from 'rate-limiter-flexible';
|
import {RateLimiterRedis} from 'rate-limiter-flexible';
|
||||||
|
|
||||||
export default async (options) => {
|
export default async (flecks, options) => {
|
||||||
const storeClient = createClient();
|
const storeClient = createClient();
|
||||||
// @todo node-redis@4
|
// @todo node-redis@4
|
||||||
// await storeClient.connect();
|
// await storeClient.connect();
|
||||||
|
|
|
@ -55,10 +55,13 @@ export default {
|
||||||
'@flecks/server/up': async (flecks) => {
|
'@flecks/server/up': async (flecks) => {
|
||||||
if (flecks.fleck('@flecks/http/server')) {
|
if (flecks.fleck('@flecks/http/server')) {
|
||||||
const {http} = flecks.get('@flecks/governor/server');
|
const {http} = flecks.get('@flecks/governor/server');
|
||||||
const limiter = await createLimiter({
|
const limiter = await createLimiter(
|
||||||
|
flecks,
|
||||||
|
{
|
||||||
keyPrefix: '@flecks/governor.http.request.route',
|
keyPrefix: '@flecks/governor.http.request.route',
|
||||||
...http,
|
...http,
|
||||||
});
|
},
|
||||||
|
);
|
||||||
flecks.set('$flecks/governor.http.limiter', limiter);
|
flecks.set('$flecks/governor.http.limiter', limiter);
|
||||||
}
|
}
|
||||||
if (flecks.fleck('@flecks/socket/server')) {
|
if (flecks.fleck('@flecks/socket/server')) {
|
||||||
|
@ -70,17 +73,23 @@ export default {
|
||||||
.map(async ([name, Packet]) => (
|
.map(async ([name, Packet]) => (
|
||||||
[
|
[
|
||||||
name,
|
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);
|
flecks.set('$flecks/governor.packet.limiters', limiters);
|
||||||
const {socket} = flecks.get('@flecks/governor/server');
|
const {socket} = flecks.get('@flecks/governor/server');
|
||||||
const limiter = await createLimiter({
|
const limiter = await createLimiter(
|
||||||
|
flecks,
|
||||||
|
{
|
||||||
keyPrefix: '@flecks/governor.socket.request.socket',
|
keyPrefix: '@flecks/governor.socket.request.socket',
|
||||||
...socket,
|
...socket,
|
||||||
});
|
},
|
||||||
|
);
|
||||||
flecks.set('$flecks/governor.socket.limiter', limiter);
|
flecks.set('$flecks/governor.socket.limiter', limiter);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
const env = require('../environment');
|
module.exports = (flecks) => (neutrino) => {
|
||||||
|
|
||||||
module.exports = () => (neutrino) => {
|
|
||||||
if ('production' === neutrino.config.get('mode')) {
|
if ('production' === neutrino.config.get('mode')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const {devHost, devPort, devPublic} = env();
|
const {devHost, devPort, devPublic} = flecks.get('@flecks/http/server');
|
||||||
neutrino.config.devServer
|
neutrino.config.devServer
|
||||||
.hot(false)
|
.hot(false)
|
||||||
.host(devHost)
|
.host(devHost)
|
||||||
|
|
|
@ -9,7 +9,7 @@ const runtime = require('./runtime');
|
||||||
const targets = require('./targets');
|
const targets = require('./targets');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
FLECKS_ROOT = process.cwd(),
|
FLECKS_CORE_ROOT = process.cwd(),
|
||||||
} = process.env;
|
} = process.env;
|
||||||
|
|
||||||
const debug = D('@flecks/http/http.neutrino.js');
|
const debug = D('@flecks/http/http.neutrino.js');
|
||||||
|
@ -22,14 +22,14 @@ debug('bootstrapped');
|
||||||
const config = {
|
const config = {
|
||||||
options: {
|
options: {
|
||||||
output: 'dist',
|
output: 'dist',
|
||||||
root: FLECKS_ROOT,
|
root: FLECKS_CORE_ROOT,
|
||||||
},
|
},
|
||||||
use: [
|
use: [
|
||||||
({config}) => {
|
({config}) => {
|
||||||
config
|
config
|
||||||
.plugin('environment')
|
.plugin('environment')
|
||||||
.use(EnvironmentPlugin, [{
|
.use(EnvironmentPlugin, [{
|
||||||
FLECKS_BUILD_TARGET: 'client',
|
FLECKS_CORE_BUILD_TARGET: 'client',
|
||||||
}]);
|
}]);
|
||||||
},
|
},
|
||||||
targets(flecks),
|
targets(flecks),
|
||||||
|
@ -63,7 +63,7 @@ else {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
// Configure dev server.
|
// Configure dev server.
|
||||||
config.use.push(devServer());
|
config.use.push(devServer(flecks));
|
||||||
// Build the client runtime.
|
// Build the client runtime.
|
||||||
config.use.push(runtime(flecks));
|
config.use.push(runtime(flecks));
|
||||||
// Output configuration.
|
// Output configuration.
|
||||||
|
|
|
@ -5,15 +5,14 @@ const {realpathSync} = require('fs');
|
||||||
const {require: R} = require('@flecks/core/server');
|
const {require: R} = require('@flecks/core/server');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
FLECKS_HTTP_OUTPUT = 'http',
|
FLECKS_CORE_ROOT = process.cwd(),
|
||||||
FLECKS_ROOT = process.cwd(),
|
|
||||||
} = process.env;
|
} = process.env;
|
||||||
|
|
||||||
module.exports = (flecks) => (neutrino) => {
|
module.exports = (flecks) => (neutrino) => {
|
||||||
const {options} = neutrino;
|
const {options} = neutrino;
|
||||||
const {output: originalOutput} = options;
|
const {output: originalOutput} = options;
|
||||||
neutrino.config.resolve.modules.merge([
|
neutrino.config.resolve.modules.merge([
|
||||||
join(FLECKS_ROOT, 'node_modules'),
|
join(FLECKS_CORE_ROOT, 'node_modules'),
|
||||||
'node_modules',
|
'node_modules',
|
||||||
]);
|
]);
|
||||||
options.root = realpathSync(dirname(R.resolve(join(flecks.resolve('@flecks/http'), 'entry.js'))));
|
options.root = realpathSync(dirname(R.resolve(join(flecks.resolve('@flecks/http'), 'entry.js'))));
|
||||||
|
@ -23,5 +22,5 @@ module.exports = (flecks) => (neutrino) => {
|
||||||
entry: './client/tests',
|
entry: './client/tests',
|
||||||
title: 'Testbed',
|
title: 'Testbed',
|
||||||
};
|
};
|
||||||
options.output = join(originalOutput, FLECKS_HTTP_OUTPUT);
|
options.output = join(originalOutput, flecks.get('@flecks/http/server.output'));
|
||||||
};
|
};
|
||||||
|
|
|
@ -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,
|
|
||||||
});
|
|
|
@ -8,11 +8,8 @@ import express from 'express';
|
||||||
import httpProxy from 'http-proxy';
|
import httpProxy from 'http-proxy';
|
||||||
import flatten from 'lodash.flatten';
|
import flatten from 'lodash.flatten';
|
||||||
|
|
||||||
import env from './environment';
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
FLECKS_HTTP_OUTPUT = 'http',
|
FLECKS_CORE_ROOT = process.cwd(),
|
||||||
FLECKS_ROOT = process.cwd(),
|
|
||||||
NODE_ENV,
|
NODE_ENV,
|
||||||
} = process.env;
|
} = process.env;
|
||||||
|
|
||||||
|
@ -28,8 +25,9 @@ export const createHttpServer = async (flecks) => {
|
||||||
devHost,
|
devHost,
|
||||||
devPort,
|
devPort,
|
||||||
host,
|
host,
|
||||||
|
output,
|
||||||
port,
|
port,
|
||||||
} = env();
|
} = flecks.get('@flecks/http/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);
|
||||||
|
@ -90,18 +88,18 @@ export const createHttpServer = async (flecks) => {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Serve the document root, sans index.
|
// 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.
|
// Tests bypass middleware and stream processing.
|
||||||
app.get('/tests.html', (req, res) => {
|
app.get('/tests.html', (req, res) => {
|
||||||
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
|
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);
|
stream.pipe(res);
|
||||||
});
|
});
|
||||||
// Fallback to serving HTML.
|
// Fallback to serving HTML.
|
||||||
app.get('*', routeMiddleware, async (req, res) => {
|
app.get('*', routeMiddleware, async (req, res) => {
|
||||||
if (req.accepts('text/html')) {
|
if (req.accepts('text/html')) {
|
||||||
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
|
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);
|
deliverHtmlStream(stream, flecks, req, res);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -20,7 +20,7 @@ export default {
|
||||||
}
|
}
|
||||||
// Otherwise, spawn `webpack-dev-server` (WDS).
|
// Otherwise, spawn `webpack-dev-server` (WDS).
|
||||||
const localEnv = {
|
const localEnv = {
|
||||||
FLECKS_BUILD_LIST: 'http',
|
FLECKS_CORE_BUILD_LIST: 'http',
|
||||||
};
|
};
|
||||||
const spawnArgs = [
|
const spawnArgs = [
|
||||||
'--mode', 'development',
|
'--mode', 'development',
|
||||||
|
@ -33,6 +33,12 @@ export default {
|
||||||
delete neutrinoConfigs.http;
|
delete neutrinoConfigs.http;
|
||||||
},
|
},
|
||||||
'@flecks/core/config': () => ({
|
'@flecks/core/config': () => ({
|
||||||
|
devHost: 'localhost',
|
||||||
|
devPort: 32341,
|
||||||
|
devPublic: undefined,
|
||||||
|
host: '0.0.0.0',
|
||||||
|
output: 'http',
|
||||||
|
port: 32340,
|
||||||
'stream.html': ['...'],
|
'stream.html': ['...'],
|
||||||
'request.route': [],
|
'request.route': [],
|
||||||
'request.socket': [],
|
'request.socket': [],
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
const {
|
export default (flecks) => ({
|
||||||
REDIS_PORT = 6379,
|
|
||||||
} = process.env;
|
|
||||||
|
|
||||||
export default () => ({
|
|
||||||
redis: {
|
redis: {
|
||||||
image: 'redis',
|
image: 'redis',
|
||||||
mount: '/data',
|
mount: '/data',
|
||||||
ports: {[REDIS_PORT]: 6379},
|
ports: {[flecks.get('@flecks/redis/server.port')]: 6379},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
import {createClient} from 'redis';
|
import {createClient} from 'redis';
|
||||||
|
|
||||||
const {
|
export default (flecks, opts = {}) => {
|
||||||
REDIS_HOST = 'localhost',
|
const {
|
||||||
REDIS_PORT = 6379,
|
host,
|
||||||
} = process.env;
|
port,
|
||||||
|
} = flecks.get('@flecks/redis/server');
|
||||||
export default (opts = {}) => (
|
return createClient({
|
||||||
createClient({
|
url: `redis://${host}:${port}`,
|
||||||
url: `redis://${opts.host || REDIS_HOST}:${opts.port || REDIS_PORT}`,
|
|
||||||
...opts,
|
...opts,
|
||||||
})
|
});
|
||||||
);
|
};
|
||||||
|
|
|
@ -29,9 +29,13 @@ export const keys = (client, pattern) => safeKeys(client, pattern, 0);
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
[Hooks]: {
|
[Hooks]: {
|
||||||
|
'@flecks/core/config': () => ({
|
||||||
|
host: 'localhost',
|
||||||
|
port: 6379,
|
||||||
|
}),
|
||||||
'@flecks/docker/containers': containers,
|
'@flecks/docker/containers': containers,
|
||||||
'@flecks/repl/context': () => ({
|
'@flecks/repl/context': (flecks) => ({
|
||||||
redisClient: createClient(),
|
redisClient: createClient(flecks),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -12,16 +12,16 @@ const RedisStore = ConnectRedis(session);
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
[Hooks]: {
|
[Hooks]: {
|
||||||
'@flecks/user/session': async () => {
|
'@flecks/user/session': async (flecks) => {
|
||||||
const client = createClient({legacyMode: true});
|
const client = createClient(flecks, {legacyMode: true});
|
||||||
await client.connect();
|
await client.connect();
|
||||||
return {
|
return {
|
||||||
store: new RedisStore({client}),
|
store: new RedisStore({client}),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
'@flecks/socket/server': async () => {
|
'@flecks/socket/server': async (flecks) => {
|
||||||
const pubClient = createClient();
|
const pubClient = createClient(flecks);
|
||||||
const subClient = createClient();
|
const subClient = createClient(flecks);
|
||||||
await Promise.all([pubClient.connect(), subClient.connect()]);
|
await Promise.all([pubClient.connect(), subClient.connect()]);
|
||||||
debug('creating adapter');
|
debug('creating adapter');
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -3,6 +3,10 @@ import {Hooks} from '@flecks/core';
|
||||||
export default {
|
export default {
|
||||||
[Hooks]: {
|
[Hooks]: {
|
||||||
'@flecks/core/config': () => ({
|
'@flecks/core/config': () => ({
|
||||||
|
hot: false,
|
||||||
|
inspect: false,
|
||||||
|
profile: false,
|
||||||
|
start: false,
|
||||||
up: ['...'],
|
up: ['...'],
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,7 +8,7 @@ module.exports = (flecks) => (neutrino) => {
|
||||||
// Inject flecks configuration.
|
// Inject flecks configuration.
|
||||||
const paths = Object.keys(resolver);
|
const paths = Object.keys(resolver);
|
||||||
const source = [
|
const source = [
|
||||||
"process.env.FLECKS_BUILD_TARGET = 'server';",
|
"process.env.FLECKS_CORE_BUILD_TARGET = 'server';",
|
||||||
'module.exports = (async () => ({',
|
'module.exports = (async () => ({',
|
||||||
` config: ${JSON.stringify(config)},`,
|
` config: ${JSON.stringify(config)},`,
|
||||||
' flecks: Object.fromEntries(await Promise.all([',
|
' flecks: Object.fromEntries(await Promise.all([',
|
||||||
|
|
|
@ -9,11 +9,7 @@ const D = require('debug');
|
||||||
const runtime = require('./runtime');
|
const runtime = require('./runtime');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
FLECKS_HOT = false,
|
FLECKS_CORE_ROOT = process.cwd(),
|
||||||
FLECKS_INSPECT = false,
|
|
||||||
FLECKS_PROFILE = false,
|
|
||||||
FLECKS_ROOT = process.cwd(),
|
|
||||||
FLECKS_START_SERVER = false,
|
|
||||||
} = process.env;
|
} = process.env;
|
||||||
|
|
||||||
const debug = D('@flecks/server/server.neutrino.js');
|
const debug = D('@flecks/server/server.neutrino.js');
|
||||||
|
@ -22,15 +18,22 @@ debug('bootstrapping flecks...');
|
||||||
const flecks = Flecks.bootstrap();
|
const flecks = Flecks.bootstrap();
|
||||||
debug('bootstrapped');
|
debug('bootstrapped');
|
||||||
|
|
||||||
|
const {
|
||||||
|
hot,
|
||||||
|
inspect,
|
||||||
|
profile,
|
||||||
|
start: isStarting,
|
||||||
|
} = flecks.get('@flecks/server');
|
||||||
|
|
||||||
const entry = (neutrino) => {
|
const entry = (neutrino) => {
|
||||||
const entries = neutrino.config.entry('index');
|
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');
|
entries.add('@flecks/server/entry');
|
||||||
};
|
};
|
||||||
|
|
||||||
// Augment the application-starting configuration.
|
// Augment the application-starting configuration.
|
||||||
const start = (neutrino) => {
|
const start = (neutrino) => {
|
||||||
if (FLECKS_START_SERVER) {
|
if (isStarting) {
|
||||||
neutrino.use(startServer({name: 'index.js'}));
|
neutrino.use(startServer({name: 'index.js'}));
|
||||||
}
|
}
|
||||||
if (!neutrino.config.plugins.has('start-server')) {
|
if (!neutrino.config.plugins.has('start-server')) {
|
||||||
|
@ -42,13 +45,13 @@ const start = (neutrino) => {
|
||||||
const options = args[0];
|
const options = args[0];
|
||||||
options.keyboard = false;
|
options.keyboard = false;
|
||||||
// HMR.
|
// HMR.
|
||||||
options.signal = true;
|
options.signal = !!hot;
|
||||||
// Debugging.
|
// Debugging.
|
||||||
if (FLECKS_INSPECT) {
|
if (inspect) {
|
||||||
options.nodeArgs.push('--inspect');
|
options.nodeArgs.push('--inspect');
|
||||||
}
|
}
|
||||||
// Profiling.
|
// Profiling.
|
||||||
if (FLECKS_PROFILE) {
|
if (profile) {
|
||||||
options.nodeArgs.push('--prof');
|
options.nodeArgs.push('--prof');
|
||||||
}
|
}
|
||||||
// Bail hard on unhandled rejections and report.
|
// Bail hard on unhandled rejections and report.
|
||||||
|
@ -66,7 +69,7 @@ const compiler = flecks.invokeFleck(
|
||||||
const config = {
|
const config = {
|
||||||
options: {
|
options: {
|
||||||
output: 'dist',
|
output: 'dist',
|
||||||
root: FLECKS_ROOT,
|
root: FLECKS_CORE_ROOT,
|
||||||
},
|
},
|
||||||
use: [
|
use: [
|
||||||
entry,
|
entry,
|
||||||
|
@ -84,7 +87,7 @@ else {
|
||||||
});
|
});
|
||||||
config.use.unshift(node({
|
config.use.unshift(node({
|
||||||
clean: false,
|
clean: false,
|
||||||
hot: FLECKS_HOT,
|
hot,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
// Stub out non-server-friendly modules on the server.
|
// Stub out non-server-friendly modules on the server.
|
||||||
|
@ -123,7 +126,7 @@ config.use.push(runtime(flecks));
|
||||||
// Give the resolver a helping hand.
|
// Give the resolver a helping hand.
|
||||||
config.use.push((neutrino) => {
|
config.use.push((neutrino) => {
|
||||||
neutrino.config.resolve.modules.merge([
|
neutrino.config.resolve.modules.merge([
|
||||||
join(FLECKS_ROOT, 'node_modules'),
|
join(FLECKS_CORE_ROOT, 'node_modules'),
|
||||||
'node_modules',
|
'node_modules',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
import D from 'debug';
|
import D from 'debug';
|
||||||
|
|
||||||
|
const {
|
||||||
|
NODE_ENV,
|
||||||
|
} = process.env;
|
||||||
|
|
||||||
const debug = D('@flecks/socket/acceptor');
|
const debug = D('@flecks/socket/acceptor');
|
||||||
|
|
||||||
export default (socket) => async (packet, fn) => {
|
export default (socket) => async (packet, fn) => {
|
||||||
|
@ -17,9 +21,6 @@ export default (socket) => async (packet, fn) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
debug('acceptor error: %O', error);
|
debug('acceptor error: %O', error);
|
||||||
const {
|
|
||||||
NODE_ENV,
|
|
||||||
} = process.env;
|
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
fn({
|
fn({
|
||||||
code: error.code || 500,
|
code: error.code || 500,
|
||||||
|
|
|
@ -5,12 +5,13 @@ import expressSession from 'express-session';
|
||||||
|
|
||||||
const debug = D('@flecks/user/session');
|
const debug = D('@flecks/user/session');
|
||||||
|
|
||||||
const {
|
|
||||||
FLECKS_USER_COOKIE_SECRET = 'UNSAFE_DEV_COOKIE',
|
|
||||||
} = process.env;
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
[Hooks]: {
|
[Hooks]: {
|
||||||
|
'@flecks/core/config': () => ({
|
||||||
|
cookieSecret: (
|
||||||
|
'Set the FLECKS_ENV_FLECKS_USER_SESSION_SERVER_cookieSecret environment variable!'
|
||||||
|
),
|
||||||
|
}),
|
||||||
'@flecks/http/server/request.route': (flecks) => {
|
'@flecks/http/server/request.route': (flecks) => {
|
||||||
const urle = express.urlencoded({extended: true});
|
const urle = express.urlencoded({extended: true});
|
||||||
return (req, res, next) => {
|
return (req, res, next) => {
|
||||||
|
@ -37,7 +38,7 @@ export default {
|
||||||
resave: false,
|
resave: false,
|
||||||
sameSite: true,
|
sameSite: true,
|
||||||
saveUninitialized: false,
|
saveUninitialized: false,
|
||||||
secret: FLECKS_USER_COOKIE_SECRET,
|
secret: flecks.get('@flecks/user/session/server.cookieSecret'),
|
||||||
...await flecks.invokeReduceAsync('@flecks/user/session'),
|
...await flecks.invokeReduceAsync('@flecks/user/session'),
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user