sample route actions for jwt + consola demo

This commit is contained in:
Philipp Dormann 2020-11-24 19:54:22 +01:00
parent 6b46a0a69e
commit 8140d76240
1 changed files with 19 additions and 5 deletions

View File

@ -1,18 +1,32 @@
import * as dotenvSafe from 'dotenv-safe'; import * as dotenvSafe from 'dotenv-safe';
import express from 'express'; import express from 'express';
import consola from 'consola';
import * as jwt from 'jsonwebtoken';
import { createConnection } from 'typeorm'; import { createConnection } from 'typeorm';
dotenvSafe.config(); dotenvSafe.config();
const app = express();
const PORT = process.env.APP_PORT || 4010;
createConnection() createConnection()
.then((connection) => { .then((connection) => {
const app = express(); app.get('/', (req, res) => {
const PORT = process.env.APP_PORT || 4010; const encoded = jwt.sign({ key: 'value' }, 'secret');
app.get('/', (req, res) => res.send('Express + TypeScript Server')); consola.info(encoded);
return res.send('Express + TypeScript Server');
});
app.listen(PORT, () => { app.listen(PORT, () => {
console.log(`⚡️[server]: Server is running at http://localhost:${PORT}`); consola.success(`⚡️[server]: Server is running at http://localhost:${PORT}`);
}); });
}) })
.catch((err) => { .catch((err) => {
console.log(err); consola.error(err);
app.get('/', (req, res) => {
const encoded = jwt.sign({ key: 'value' }, 'secret');
consola.info(encoded);
return res.send('Express + TypeScript Server');
});
app.listen(PORT, () => {
consola.success(`⚡️[server]: Server is running at http://localhost:${PORT}`);
});
}); });