-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from kiwijos/codebase-cleanup
Codebase cleanup
- Loading branch information
Showing
16 changed files
with
169 additions
and
110 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import express, { Express } from "express"; | ||
import cors from "cors"; | ||
import bodyParser from "body-parser"; | ||
|
||
import delayed from "../routes/delayed"; | ||
import tickets from "../routes/tickets"; | ||
import codes from "../routes/codes"; | ||
|
||
const app: Express = express(); | ||
|
||
app.use(cors()); | ||
app.options("*", cors()); | ||
|
||
app.disable("x-powered-by"); | ||
|
||
app.use(bodyParser.json()); // for parsing application/json | ||
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded | ||
|
||
app.use("/delayed", delayed); | ||
app.use("/tickets", tickets); | ||
app.use("/codes", codes); | ||
|
||
export default app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import mongoose from "mongoose"; | ||
|
||
async function startDb() { | ||
let uri = `mongodb+srv://${process.env.ATLAS_USERNAME}:${process.env.ATLAS_PASSWORD}@trains.9gkcdmg.mongodb.net/?retryWrites=true&w=majority`; | ||
|
||
if (process.env.NODE_ENV === "test") { | ||
uri = process.env.MONGO_URI_TEST; | ||
} | ||
|
||
await mongoose.connect(uri, { dbName: "trains" }); | ||
} | ||
|
||
export default startDb; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import app from "./app"; | ||
|
||
import http from "http"; | ||
import { Server } from "socket.io"; | ||
|
||
const server = http.createServer(app); | ||
|
||
interface ServerToClientEvents { | ||
noArg: () => void; | ||
basicEmit: (a: number, b: string, c: Buffer) => void; | ||
withAck: (d: string, callback: (e: number) => void) => void; | ||
} | ||
|
||
interface ClientToServerEvents { | ||
hello: () => void; | ||
} | ||
|
||
interface InterServerEvents { | ||
ping: () => void; | ||
} | ||
|
||
interface SocketData { | ||
name: string; | ||
age: number; | ||
} | ||
|
||
const io = new Server<ClientToServerEvents, ServerToClientEvents, InterServerEvents, SocketData>( | ||
server, | ||
{ | ||
cors: { | ||
origin: [ | ||
"http://localhost:9000", | ||
"http://localhost:5173", | ||
"https://localhost:5000", | ||
"https://master--fastidious-sunburst-6bd3ae.netlify.app/" | ||
], | ||
methods: ["GET", "POST", "PUT", "DELETE"] | ||
} | ||
} | ||
); | ||
|
||
export { server, io }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import dotenv from "dotenv"; | ||
dotenv.config(); | ||
|
||
import { server, io } from "./config/server"; | ||
import fetchTrainPositions from "./controllers/trains"; | ||
import startDb from "./config/database"; | ||
|
||
const port = process.env.PORT || 1337; | ||
|
||
server.listen(port, (): void => { | ||
console.log(`App listening on port ${port}`); | ||
}); | ||
|
||
startDb().catch((err) => console.log(err)); | ||
|
||
// Temporary work-around preventing sockets from keeping | ||
// the server alive even after all tests have run | ||
if (process.env.NODE_ENV !== "test") { | ||
fetchTrainPositions(io); | ||
} | ||
|
||
// Export listening app for testing | ||
export default server; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
interface ErrorResponse { | ||
errors: { | ||
status: number; | ||
source: string; | ||
title: string; | ||
message: string; | ||
status: number; | ||
source: string; | ||
title: string; | ||
message: string; | ||
}; | ||
} | ||
} | ||
|
||
export default ErrorResponse; | ||
export default ErrorResponse; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ interface TrainPosition { | |
speed: number; | ||
} | ||
|
||
export default TrainPosition; | ||
export default TrainPosition; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type TrainPosition from "./TrainPosition.model"; | ||
|
||
interface TrainPositions { | ||
[trainNumber: string]: TrainPosition; | ||
} | ||
|
||
export default TrainPositions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters