- TypeScript 94.6%
- JavaScript 4.9%
- Dockerfile 0.5%
Signal to the server hosting the dev environment to pull the image again after a new develop image has been produced. |
||
|---|---|---|
| .forgejo/workflows | ||
| .vscode | ||
| docs | ||
| scripts | ||
| src | ||
| test | ||
| .dockerignore | ||
| .gitignore | ||
| Dockerfile | ||
| package.json | ||
| pnpm-lock.yaml | ||
| README.md | ||
| tsconfig.json | ||
Nodewrangler - Server for HydraSlayer
Server software for hosting the HTTP API which HydraSlayer clients talk to.
Available Scripts
In the project directory, you can run:
./scripts/migrate.js up
To initialize a development database.
./scripts/seed.js up
To insert test data into the database.
./scripts/repl.js
Interactive REPL prompt connected to the database.
Sample usage
// Execute raw SQL queries
> await sl.query("SELECT name FROM Users;")
// Query fields on a model.
> await User.findAll({ attributes: ["id", "name"], raw: true })
// Modify data through a model
> u = await User.findOne({ where: { name: "Hornwitser" }})
> u.name = "Rawr"
> await u.save()
pnpm run dev
To start the app in dev mode.
Open http://localhost:3000 to view it in the browser.
pnpm run build
Compile TypeScript source into runnable JavaScript.
pnpm run start
For production mode
Requires a build done with pnpm run build.
pnpm run test
Run the test cases.
Learn More
To learn Fastify, check out the Fastify documentation.
Database Migrations
The ./scripts/migrate.js script provides a simple interface to initialize a new database schema and migrate existing schemas to new versions.
By default the dev.sqlite database is targeted unless the SEQUELIZE_DATABASE_URI environment variable is set up to point to a different database.
With the right database targeted running ./scripts/migrate.js up should be all that is needed to convert the database schema to what the deployed code expects.
See ./scripts/migrate.js --help for available commands.
Creating Migrations
When you add, alter or remove models you will need to create a migration to apply this change for existing deployments.
To help with setting up migrations run ./scripts/migrate.js create --skip-verify --prefix NONE --name xx-migration-name.ts (where xx is the next available number in the src/migrations folder) to generate the boilerplate for a migration in src/migrations.
Then add the newly created migration to src/migrations/index.ts.
Once you've written the migration code validate that the schema created from running the migrations is identical to the schema created by running a sync operation by running the ./scripts/diff-sync-migrate.js script.
Configuration
Nodewrangler uses environment variables to configue options to run with. The following environment variables are recognised.
CONNECTION_STRING (deprecated)
MongoDB connection string to connect to the old database with.
Only used by ./src/dump_mongodb.ts.
FASTIFY_ADDRESS
Address to bind HTTP server on.
Defaults to 0.0.0.0 inside docker or kubernetes containers, localhost otherwise.
FASTIFY_PORT
Port to bind HTTP server on.
Defaults to 3000.
NODE_ENV
Indicates the environment the app is runned in. Recognised values are:
production
Normal production environment. Use this when deploying the app.testing
Set when running the unit test and should not be used otherwise. Destroys the configured database and exposes the fastify instance from the app as a plugin.development
Should only be used when running a local development build. Sets defaults database todev.sqlite. May enable insecure features meant only for helping with testing during development.
Defaults to production.
GOOGLE_OAUTH_ID
OAuth 2.0 client indentifier used for implementing login with Google. You can obtain a Google OAuth 2.0 identifier and secret from the Google Cloud Console
GOOGLE_OAUTH_SECRET_FILE
Path to file containing the OAuth 2.0 client secret used for implementing login with Google.
GOOGLE_OAUTH_SECRET (deprecated)
Insecure environment variable based way of passing the Google OAuth 2.0 client secret.
GOOGLE_OAUTH_REDIRECT_ORIGINS
Semicolon separated list of origins to accept OAuth 2.0 authentication requests from in addition to PUBLIC_URL.
Each origin will be matached against the Referer header and if the protocol, hostname, and port matches it will be used to construct the redirect URI passed on to google by resolving api/auth/google/callback relative to the origin.
For example setting this to http://localhost:5173/ will make a request with a Referer of http://localhost:5173/login use a redirect URI of https://localhost:5173/api/auth/google/callback.
If that URI is allowed in the google console this makes it possible to log in to a locally running dev client, provided its proxy configuration is set to forward requests to /api to this server.
PUBLIC_URL
Absolute URL of the location where the hosted HTTP server is accessible from. This is used for creating the redirect uri for OAuth 2.0 authentication and setting the server in the swagger UI.
Defaults to http://localhost:3000
SEQUELIZE_DATABASE_URI
Sequelize database connection URI. Only MariaDB is supported in a production installation. Should be a string formatted like:
mariadb://user:password@host:port/database
In a development installation sqlite may also be used via a string formatted like:
sqlite:path/to/database.sqlite
Defaults to sqlite:dev.sqlite if NODE_ENV is set to development.
SEQUELIZE_DATABASE_PASSWORD_FILE
Optional variable to set a path to a file containing only the password to use for connecting to the database.
This exists as a separate from the URI to simplify secret configuration for production, if not set the password in SEQUELIZE_DATABASE_URI will be used instead.
SEQUELIZE_DATABASE_PASSWORD (deprecated)
Insecure environment variable based way of passing the database password.