Goxidize
A link shortener.
Perquisites
- Rust 1.56+
- npm CLI and Node.js
- Any officially supported PostgreSQL
Build
Before building the project, please create a .env
file with a valid PostgreSQL URL, such as the following.
DATABASE_URL=postgresql://localhost:5432/goxidize
Then, run the database migrations.
sqlx migrate run
This database is queried against for compile-time checks done by sqlx
.
If you don't have a database set up, sqlx
will check against sqlx-data.json
. To generate this file, run cargo sqlx prepare -- --lib
and cargo sqlx prepare --check -- --lib
. Note that you will still need a working database to run the tests.
Development
The Parcel development server supports auto-reloading for frontend assets. Use the following file to let the Parcel server proxy requests to the backend.
const { createProxyMiddleware } = require("http-proxy-middleware");
module.exports = function (app) {
app.use(
createProxyMiddleware(["/**", "!/", "!**/*.html", "!**/*.js", "!*.css", "!**/*.css", "!**/*.map"], {
target: "http://localhost:8000/",
})
);
};
Run the following to start the servers.
cargo run # use cargo watch for auto-reloading
# then on a separate terminal, run
# `npm install` if you have not installed the dependencies, and
npm start
Production
npm run build
Configuration
A YAML file is used for configuration. This affects the run-time behaviour of the program.
# configuration.yml
port: 8000
database:
url: postgresql://localhost:5432
name: goxidize
debug: true
Deployment
An example of deployment using docker-compose
is provided below.
# docker-compose.yml
version: '3'
services:
db:
image: postgres:14
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: goxidize
LANG: C.UTF-8
volumes:
- dbdata:/var/lib/postgresql/data
goxidize:
image: ghcr.io/caizixian/goxidize:master
restart: always
depends_on:
- "db"
ports:
- "8000:8000"
environment:
GOXIDIZE_HOST: "0.0.0.0"
GOXIDIZE_PORT: "8000"
GOXIDIZE_DATABASE_URL: "postgresql://postgres:password@db:5432"
GOXIDIZE_DATABASE_NAME: "goxidize"
GOXIDIZE_DEBUG: "false"
volumes:
dbdata:
License
Except as otherwise noted (e.g., in individual files), the project is licensed under the Apache License, Version 2.0 LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0 or the MIT license LICENSE-MIT or http://opensource.org/licenses/MIT, at your option.