Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Build Koa applications in a spark.
KoaSpark is a boilerplate-as-a-library for creating Koa apps, it includes out-of-the-box many koa plugins that
you normally need for an app like koa-body
, koa-cors
and koa-router
, plus many other useful features
like the automatic generation of OpenAPI definitions.
All of this is typically found in templates and boilerplates via cloning a base git repo and then editing it or via a CLI that generates code, this approach works but keep your app updated when a new version of the template is released is a nightmare.
KoaSpark has a differnet approach, it doesn't generate any code, it's just an import
able library that provides an alternative
to const app = new Koa()
: const app = createApp(config, options)
and you have a KoaApp ready to use.
npm install koa-spark
# or
yarn add koa-spark
Then create the app:
import { createApp } from 'koa-spark'
const app = createApp()
if (require.main === module) {
app.startServer()
}
In Koa Spark, there are 2 levels of configuration, at the app level AppConfig
and at the framework level SparkOptions
.
They are both passed to the createApp(AppConfig, SparkOptions)
function.
The app configuration holds environment-specific configurations, like secrets, connection info, etc. that should be changed by the final user if you redistribute the app, or changed when you deploy in production.
The AppConfig can be configured via environmental variables and/or .env
files, Koa Spark will automatically initialize the AppConfig
properties decorated with @Field()
with the corresponding environment variable. Note that AppConfig properties are written in camelCase
but env variables are written in UPPER_SNAKE_CASE
.
// config.ts
import { AppConfig, Field } from 'koa-spark'
class MyAppConfig extends AppConfig {
@Field({ default: 'test@localhost' }) // env: FROM_ADDRESS
fromAddress!: string
@Field() // env: GCLOUD_STORAGE_BUCKET
gcloudStorageBucket!: string
@Field({ default: 'mongodb://localhost/thedb' })
mongodbConnectionUri!: string
@Field()
sendgridApiKey!: string
}
export default new MyAppConfig()
And its relative .env
file:
# .env
FROM_ADDRESS=luca@mail.com
GCLOUD_STORAGE_BUCKET=my_bucket_production
You can have multiple .env
files, one per each environment, named .env.<NODE_ENV>
.
Koa Spark will try to load the environment-specific file and fallback to the generic one,
for example in production will try to load .env.production
and if it's missing will load .env
.
The framework options SparkOptions
are used to configure Koa Spark itself, are more inner-configs than
AppConfig
, for example they include configurations for CORS, helmet, etc.
As for their nature, framework options are not configurable via env variables, but only via code:
const app = createApp(
config,
{
body: {
multipart: true
}
}
)
FAQs
Koa application boilerplate-less
We found that koa-spark demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.