implement base api structure with express
This commit is contained in:
parent
5aa8ca01e9
commit
46f1d97c23
|
|
@ -6,7 +6,8 @@
|
|||
"scripts": {
|
||||
"dev": "nodemon --watch src -e js,ts,json --exec 'ts-node src/index.ts'",
|
||||
"build": "tsc src/index.ts",
|
||||
"start": "node dist/index.js"
|
||||
"start": "node dist/index.js",
|
||||
"db": "prisma studio"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
import { Router } from 'express';
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
res.send('Hello World!');
|
||||
});
|
||||
|
||||
export default router;
|
||||
17
src/index.ts
17
src/index.ts
|
|
@ -1 +1,16 @@
|
|||
console.log('Hello World2');
|
||||
import express, { urlencoded, json } from 'express';
|
||||
import cors from 'cors';
|
||||
import api from '~api';
|
||||
|
||||
const port = process.env.PORT || 3000;
|
||||
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
app.use(urlencoded({ extended: true }));
|
||||
app.use(json());
|
||||
|
||||
app.use('/api', api);
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Server listening on port ${port}`);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
"outDir": "./dist",
|
||||
"strictPropertyInitialization": false,
|
||||
"paths": {
|
||||
"~/*": [
|
||||
"~*": [
|
||||
"./src/*"
|
||||
],
|
||||
"~~/*": [
|
||||
|
|
|
|||
Loading…
Reference in New Issue