Compare commits
4 Commits
619485b356
...
23df478522
Author | SHA1 | Date | |
---|---|---|---|
23df478522 | |||
0d1d3c593c | |||
5034cbfd93 | |||
ab0e925ab3 |
@ -22,8 +22,11 @@
|
||||
],
|
||||
"license": "CC-BY-NC-SA-4.0",
|
||||
"dependencies": {
|
||||
"body-parser": "^1.19.0",
|
||||
"consola": "^2.15.0",
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.17.1",
|
||||
"helmet": "^4.2.0",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"mysql": "^2.18.1",
|
||||
"pg": "^8.5.1",
|
||||
@ -31,12 +34,15 @@
|
||||
"typeorm": "^0.2.29"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/cors": "^2.8.8",
|
||||
"@types/dotenv-safe": "^8.1.1",
|
||||
"@types/express": "^4.17.9",
|
||||
"@types/helmet": "^4.0.0",
|
||||
"@types/jsonwebtoken": "^8.5.0",
|
||||
"@types/node": "^14.14.9",
|
||||
"dotenv-safe": "^8.2.0",
|
||||
"nodemon": "^2.0.6",
|
||||
"sqlite3": "^5.0.0",
|
||||
"ts-node": "^9.0.0",
|
||||
"typescript": "^4.1.2"
|
||||
},
|
||||
|
10
src/app.ts
10
src/app.ts
@ -4,6 +4,9 @@ import consola from 'consola';
|
||||
import * as jwt from 'jsonwebtoken';
|
||||
import { createConnection } from 'typeorm';
|
||||
import 'reflect-metadata';
|
||||
import { router as routerMain } from './routes/index';
|
||||
// const loaders = require('./loaders');
|
||||
import * as loaders from './loaders/index';
|
||||
|
||||
dotenvSafe.config();
|
||||
const app = express();
|
||||
@ -15,11 +18,8 @@ createConnection()
|
||||
consola.error(err);
|
||||
})
|
||||
.finally(() => {
|
||||
app.get('/', (req, res) => {
|
||||
const encoded = jwt.sign({ key: 'value' }, 'secret');
|
||||
consola.info(encoded);
|
||||
return res.send('Express + TypeScript Server');
|
||||
});
|
||||
// await loaders.init(app);
|
||||
app.use('/api/', routerMain);
|
||||
app.listen(PORT, () => {
|
||||
consola.success(`⚡️[server]: Server is running at http://localhost:${PORT}`);
|
||||
});
|
||||
|
0
src/loaders/.gitkeep
Normal file
0
src/loaders/.gitkeep
Normal file
14
src/loaders/index.ts
Normal file
14
src/loaders/index.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import express from 'express';
|
||||
import bodyParser from 'body-parser';
|
||||
import cors from 'cors';
|
||||
|
||||
export default async (app) => {
|
||||
app.get('/status', (req, res) => res.status(200).end());
|
||||
app.enable('trust proxy');
|
||||
|
||||
app.use(cors());
|
||||
// app.use(bodyParser.urlencoded({ extended: false }));
|
||||
|
||||
// more middlewares
|
||||
return app;
|
||||
};
|
9
src/routes/index.ts
Normal file
9
src/routes/index.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import express from 'express';
|
||||
const router = express.Router();
|
||||
router.use('/v1/', (req, res) => {
|
||||
return res.send('Express + TypeScript Server');
|
||||
});
|
||||
router.use('*', (req, res) => {
|
||||
return res.status(404).send('404');
|
||||
});
|
||||
export { router };
|
Loading…
x
Reference in New Issue
Block a user