feat(express backend): basic structure implemented
This commit is contained in:
1 parent
6b1bde7a5d
commit
84d8aea1eb
7 files changed
+1800
No files matched your search
@@ -0,0 +1,23 @@
|
||||
import express, { Request, Response } from "express";
|
||||
import config from "./config";
|
||||
import cors from "cors";
|
||||
|
||||
const app = express();
|
||||
const port = config.port;
|
||||
|
||||
if (config.enableCors) {
|
||||
app.use(cors());
|
||||
}
|
||||
|
||||
app.use((req, res, next) => {
|
||||
console.log(`${req.method} request for ${req.url}`);
|
||||
next();
|
||||
});
|
||||
|
||||
app.get("/", (req: Request, res: Response) => {
|
||||
res.send("Hello, TypeScript Express!");
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Server running at http://localhost:${port}`);
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
import { configDotenv } from "dotenv";
|
||||
|
||||
configDotenv();
|
||||
|
||||
const config = {
|
||||
enableCors: false,
|
||||
port: process.env.PORT || 3000,
|
||||
};
|
||||
|
||||
export default config;
|
||||
Whitespace-only changes.
Reference in new issue
Block a user