Explore / Programming import fastify from "fastify" import cors from "@fastify/cors" import cookie from… Save Share Download ▾ Reportimport fastify from "fastify"
import cors from "@fastify/cors"
import cookie from "@fastify/cookie"
import path, { dirname } from "path"
import { fileURLToPath } from "node:url"
import Multipart from "@fastify/multipart"
import FastifyStatic from "@fastify/static"
import rateLimit from "@fastify/rate-limit"
import { FileAction } from "./actions/file.action.js"
import { UserSchemas } from "./schemas/user.schema.js"
import { AuthSchemas } from "./schemas/auth.schema.js"
import { SkillSchemas } from "./schemas/skill.schema.js"
import { StackSchemas } from "./schemas/stack.schema.js"
import type { FastifyCookieOptions } from "@fastify/cookie"
import { FabricSchemas } from "./schemas/fabric.schema.js"
import { ProjectSchemas } from "./schemas/project.schema.js"
import { ChatGPTSchemas } from "./schemas/chat-gpt.schema.js"
import { FeedbackSchemas } from "./schemas/feedback.schema.js"
import { BuildTeamSchemas } from "./schemas/build-team.schema.js"
import { AuthController } from "./controllers/auth.controller.js"
import { UserController } from "./controllers/user.controller.js"
import { SkillController } from "./controllers/skill.controller.js"
import { StackController } from "./controllers/stack.controller.js"
import { FabricController } from "./controllers/fabric.controller.js"
import { ProjectController } from "./controllers/project.controller.js"
import { ChatGPTController } from "./controllers/chat-gpt.controller.js"
import { FeedbackController } from "./controllers/feedback.controller.js"
import { PaymentMethodSchemas } from "./schemas/payment-method.schema.js"
import { EngineerRegionSchemas } from "./schemas/engineer-region.schema.js"
import { BuildTeamController } from "./controllers/build-team.controller.js"
import { ProjectTopicAreaSchemas } from "./schemas/project-topic-area.schema.js"
import { PaymentMethodController } from "./controllers/payment-method.controller.js"
import { EngineerRegionController } from "./controllers/engineer-region.controller.js"
import { ProjectTopicAreaController } from "./controllers/project-topic-area.controller.js"
// setup fastify server
const app = fastify({ logger: true })
// ---------------------------------------------------------------------------
// registered fastify dependencies
// ---------------------------------------------------------------------------
app.register(rateLimit, {
max: 10,
timeWindow: 1000,
})
app.register(cookie, {
parseOptions: {
path: "/",
secure: true,
sameSite: "none",
},
} as FastifyCookieOptions)
app.register(cors, {
origin: [
"https://devi-hub.com ",
"https://www.devi-hub.com ",
"http://devi-hub.com ",
"http://www.devi-hub.com ",
"http://localhost:3010",
],
methods: ["GET", "PUT", "POST", "PATCH", "DELETE", "OPTIONS"],
optionsSuccessStatus: 200, // some legacy browsers (IE11, various SmartTVs) choke on 204
credentials: true, //Credentials are authorization header
allowedHeaders: [
"token",
"Origin",
"Accept",
"Content-Type",
"Authorization",
"X-Requested-With",
"device-remember-token",
"Access-Control-Allow-Origin",
],
})
Show full message · 284 lines Assistant2024-09-08 07:01 UTC Copy response
The error Error: connect ECONNREFUSED 127.0.0.1:80 indicates that the connection to the server running on localhost at port 80 was refused. This typically happens when there is no server listening on that port.
Here are several steps you can take to troubleshoot and resolve this issue:
Copy first prompt
Details
Provider OpenAI
Model provenance As recorded by source dataset
Turns 1 (2 messages)
Language en
Conversation date Sep 8, 2024
Added to archive Nov 16, 2026
ID 01m7h41tq169tjg2n9z1j3rfqkSource & license Imported from WildChat-4.8M (AI2) (source ). Imported records earn no Research Points.
Upstream record: dbcdd96e1e6b891efe7cba8b7d749a36
Zhao et al., WildChat: 1M ChatGPT Interaction Logs in the Wild (ICLR 2024). Contains information from WildChat-4.8M, made available under the ODC Attribution License.
License: ODC-BY-1.0
app.register(FastifyStatic, {
// root: path.join(dirname(__dirname), "./uploads"),
root: path.join(dirname(fileURLToPath(import.meta.url)), "./uploads"),
prefix: "/api/uploads/",
})
// ---------------------------------------------------------------------------
// fastify routs
// ---------------------------------------------------------------------------
app.post("/api/file/upload", FileAction.upload)
// --------------Auth--------------
app.post(
"/api/auth/register",
{ schema: { body: AuthSchemas.register } },
AuthController.register,
)
app.post(
"/api/auth/login",
{ schema: { body: AuthSchemas.login } },
AuthController.login,
)
app.post(
"/api/auth/checkEmail",
{ schema: { body: AuthSchemas.checkEmail } },
AuthController.checkEmail,
)
app.get("/api/auth/regenerateToken", AuthController.regenerateToken)
// --------------Stack--------------
app.post(
"/api/stack/add",
{ schema: { body: StackSchemas.add } },
StackController.add,
)
app.delete(
"/api/stack/delete/:id",
{ schema: { params: StackSchemas.delete } },
StackController.delete,
)
app.get("/api/stack/getAll", StackController.getAll)
// --------------Fabric--------------
app.post(
"/api/fabric/add",
{ schema: { body: FabricSchemas.add } },
FabricController.add,
)
app.delete(
"/api/fabric/delete/:id",
{ schema: { params: FabricSchemas.delete } },
FabricController.delete,
)
app.get("/api/fabric/getAll", FabricController.getAll)
// --------------BuildTeam--------------
app.post(
"/api/buildTeam/addTeam",
{ schema: { body: BuildTeamSchemas.addTeam } },
BuildTeamController.addTeam,
)
app.post(
"/api/buildTeam/addProduct",
{ schema: { body: BuildTeamSchemas.addProduct } },
BuildTeamController.addProduct,
)
app.get("/api/buildTeam/getTeams", BuildTeamController.getTeams)
app.get("/api/buildTeam/getProducts", BuildTeamController.getProducts)
// --------------Skill--------------
app.post(
"/api/skill/add",
{ schema: { body: SkillSchemas.add } },
SkillController.add,
)
app.delete(
"/api/skill/delete/:id",
{ schema: { params: SkillSchemas.delete } },
SkillController.delete,
)
app.get("/api/skill/getAll", SkillController.getAll)
// --------------PaymentMethod--------------
app.post(
"/api/paymentMethod/add",
{ schema: { body: PaymentMethodSchemas.add } },
PaymentMethodController.add,
)
app.delete(
"/api/paymentMethod/delete/:id",
{ schema: { params: PaymentMethodSchemas.delete } },
PaymentMethodController.delete,
)
app.get("/api/paymentMethod/getAll", PaymentMethodController.getAll)
// --------------ProjectTopicArea--------------
app.post(
"/api/projectTopicArea/add",
{ schema: { body: ProjectTopicAreaSchemas.add } },
ProjectTopicAreaController.add,
)
app.delete(
"/api/projectTopicArea/delete/:id",
{ schema: { params: ProjectTopicAreaSchemas.delete } },
ProjectTopicAreaController.delete,
)
app.get("/api/projectTopicArea/getAll", ProjectTopicAreaController.getAll)
// --------------EngineerRegion--------------
app.post(
"/api/engineerRegion/add",
{ schema: { body: EngineerRegionSchemas.add } },
EngineerRegionController.add,
)
app.delete(
"/api/engineerRegion/delete/:id",
{ schema: { params: EngineerRegionSchemas.delete } },
EngineerRegionController.delete,
)
app.get("/api/engineerRegion/getAll", EngineerRegionController.getAll)
// --------------Project--------------
app.put("/api/project/updateVerified", ProjectController.updateVerified)
app.post(
"/api/project/add",
{ schema: { body: ProjectSchemas.add } },
ProjectController.add,
)
app.get(
"/api/project/getProject/:id",
{ schema: { params: ProjectSchemas.getProject } },
ProjectController.getProjectById,
)
app.get("/api/project/getPublished", ProjectController.getPublished)
app.get("/api/project/getVerified", ProjectController.getVerified)
app.get("/api/project/getRejected", ProjectController.getRejected)
// --------------Feedback--------------
app.post(
"/api/feedback/add",
{ schema: { body: FeedbackSchemas.add } },
FeedbackController.add,
)
app.get("/api/feedback/get", FeedbackController.get)
app.put("/api/feedback/update", FeedbackController.update)
// --------------User--------------
app.post("/api/user/add", UserController.add)
app.post("/api/user/updatePassword", UserController.updatePassword)
app.put(
"/api/user/editCompanyProfile",
{ schema: { body: UserSchemas.editCompanyProfile } },
UserController.editCompanyProfile,
)
app.put(
"/api/user/editEngineerProfile",
{ schema: { body: UserSchemas.editEngineerProfile } },
UserController.editEngineerProfile,
)
app.get(
"/api/user/getCompanyProfile/:id",
{ schema: { params: UserSchemas.getCompanyProfile } },
UserController.getCompanyProfile,
)
app.get(
"/api/user/getEngineerProfile/:id",
{ schema: { params: UserSchemas.getEngineerProfile } },
UserController.getEngineerProfile,
)
// --------------Gpt--------------
app.post(
"/api/gpt/buildTeam",
{ schema: { body: ChatGPTSchemas.buildTeam } },
ChatGPTController.buildTeam,
)
app.post(
"/api/gpt/buildProduct",
{ schema: { body: ChatGPTSchemas.buildProject } },
ChatGPTController.buildProject,
)
// --------------tests--------------
// app.post("/api/talks", ChatGPTController.talks)
Check Server Initialization:
Ensure that your Fastify server is running. Look for the line in your code where you start the Fastify server with something like app.listen(port, hostname). If it's missing, you'll need to add this to start the server.
Confirm Correct Port:
By default, http://localhost refers to http://localhost:80. If your Fastify server is running on a different port (e.g., 3010), ensure your request in Postman is directed to that port, like http://localhost:3010/api/stack/add.
Update Postman Request:
Modify your Postman request to use the correct port where the server is listening. From your setup, it seems localhost:3010 might be the intended port, so the request should be http://localhost:3010/api/stack/add.
Start the Fastify Server:
If you're missing the code to start the Fastify server, you can add something like the following at the end of your file:
javascript Copy code
const port = 3010; // or your desired port number
app.listen(port, '0.0.0.0', (err, address) => {
if (err) {
app.log.error(err)
process.exit(1)
}
app.log.info(`Server listening at ${address}`)
})
This code initializes the server and listens on the specified port.
Firewall/Antivirus Settings:
In rare cases, firewall or antivirus software might block the port. Verify that there are no such restrictions on your development machine.
Verify Fastify Configuration:
Ensure no errors occur when setting up Fastify plugins or routes, which might prevent the server from starting correctly. Check console logs for error messages that occur during server startup.
By following these steps, you should be able to resolve the ECONNREFUSED error by ensuring your server is up and running on the expected port before initiating a request from Postman.
Copy first response
Not yet included in a published release.