Skip to content

A Typescript/Expressjs with MySQL template, for quick development setup in Crafting Sandbox.

License

Notifications You must be signed in to change notification settings

crafting-dev/template-typescript-expressjs

Repository files navigation

Typescript/Express with MySQL template for Crafting Sandbox

This is a Typescript/Express with MySQL template, configured for quick development setup in Crafting Sandbox.

Specifications

This template defines a single /ping route:

app.get('/ping', (req, res) => {
  const pong = {
    ping: req.query.ping || 'To ping, or not to ping; that is the question.',
    received_at: new Date(),
  };

  res.json(pong);
});

This route receives a query string, and responds with the param string and the current time. For example:

$ curl --request GET 'localhost:3000/ping?ping=hello'
{"ping":"hello","received_at":"XXXX-XX-XXXXX:XX:XX.XXXX"}

Template is configured with MySQL, with the connection config available in db.ts:

const db = mysql.createConnection({
  host: process.env.MYSQL_SERVICE_HOST,
  user: 'brucewayne',
  password: 'batman',
  database: 'superhero',
});

PORT is set to 3000:

const PORT = 3000;

which is the same port value defined in App configuration below.

App Definition

The following App Definition was used to create this template:

endpoints:
- name: api
  http:
    routes:
    - pathPrefix: "/"
      backend:
        target: ts-express
        port: api
    authProxy:
      disabled: true
workspaces:
- name: ts-express
  description: Template backend using Ts/Express
  ports:
  - name: api
    port: 3000
    protocol: HTTP/TCP
  checkouts:
  - path: backend
    repo:
      git: https://github.com/crafting-dev/template-typescript-expressjs
  packages:
  - name: nodejs
    version: 16.12.0
dependencies:
- name: mysql
  serviceType: mysql
  version: '8'
  properties:
    database: superhero
    password: batman
    username: brucewayne

About

A Typescript/Expressjs with MySQL template, for quick development setup in Crafting Sandbox.

Resources

License

Stars

Watchers

Forks