Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}) {
this.addPlugin({
src: __dirname + '/plugins/browser.js',
options,
mode: 'client'
});
this.addPlugin({
src: __dirname + '/plugins/server.js',
options,
mode: 'server'
});
if (this.options.dev) {
const Server = require('@faasjs/server').Server;
const server = new Server(options.root);
if (!process.env.FaasEnv && process.env.NODE_ENV === 'development') {
process.env.FaasEnv = 'development';
}
process.env.FaasMode = 'local';
process.env.FaasLocal = `http${this.options.server.https ? 's' : ''}://${this.options.server.host}:${this.options.server.port}/_faas`;
console.log(`[faas] Mode: ${process.env.FaasMode} Env: ${process.env.FaasEnv} Local: ${process.env.FaasLocal}`);
this.addServerMiddleware({
path: '/_faas',
async handler(req: any, res: any) {
await server.processRequest(req, res);
}
});
export async function action (opts: {
port: number;
cache: boolean;
}) {
defaultsEnv();
const server = new Server(process.env.FaasRoot!, {
cache: opts.cache
});
const port = opts.port || 3000;
server.listen(port);
return true;
}