Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hw04-auth #5492

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 44 additions & 25 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,44 @@
const express = require('express')
const logger = require('morgan')
const cors = require('cors')

const contactsRouter = require('./routes/api/contacts')

const app = express()

const formatsLogger = app.get('env') === 'development' ? 'dev' : 'short'

app.use(logger(formatsLogger))
app.use(cors())
app.use(express.json())

app.use('/api/contacts', contactsRouter)

app.use((req, res) => {
res.status(404).json({ message: 'Not found' })
})

app.use((err, req, res, next) => {
res.status(500).json({ message: err.message })
})

module.exports = app
const express = require("express");
const logger = require("morgan");

const passport = require("./passport/passportConfig");

const cors = require("cors");
const corsOptions = require("./cors");

const usersRouter = require("./routes/api/usersRoutes");
const contactsRouter = require("./routes/api/contactsRoutes");

const app = express();

const formatsLogger = app.get("env") === "development" ? "dev" : "short";

app.use(logger(formatsLogger));
app.use(cors(corsOptions));
app.use(express.json());
// app.use(logger("tiny"));
app.use(passport.initialize());

app.use("/api", usersRouter);
app.use("/api", contactsRouter);

app.use((_, res, __) => {
res.status(404).json({
status: "error",
code: 404,
message: "Use api on routes: /api/users or /api/contacts ",
data: "Not found",
});
});

app.use((err, _, res, __) => {
console.log(err.stack);
res.status(500).json({
status: "fail",
code: 500,
message: err.message,
data: "Internal Server Error",
});
});

module.exports = app;
Loading