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

(update): replace require with import & update libs to latest versions #15

Merged
merged 2 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion components/Logger.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const winston = require("winston");
import winston from "winston";

/* Example logger with custom formatter
https://github.com/winstonjs/winston#combining-formats
Expand Down
45 changes: 22 additions & 23 deletions middleware.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
'use strict'
const { NextResponse } = require('next/server')
"use strict";
import { NextResponse } from "next/server";

module.exports.middleware = async function middleware(request) {
if (request.nextUrl.pathname === '/') {
if (request.nextUrl.pathname === "/") {
// This logic is only applied to /about
const response = NextResponse.next()
await new Promise((resolve) => {
setTimeout(resolve, 25)
})
response.headers.set('x-custom', 'another-header')
return response
const response = NextResponse.next();
await new Promise((resolve) => {
setTimeout(resolve, 25);
});
response.headers.set("x-custom", "another-header");
return response;
}

if (request.nextUrl.pathname === '/api') {
const response = NextResponse.next()
await new Promise((resolve) => {
setTimeout(resolve, 10)
})
return response
if (request.nextUrl.pathname === "/api") {
const response = NextResponse.next();
await new Promise((resolve) => {
setTimeout(resolve, 10);
});
return response;
}

if (request.nextUrl.pathname.startsWith('/blog')) {
const response = NextResponse.next()
await new Promise((resolve) => {
setTimeout(resolve, 10)
})
return response
if (request.nextUrl.pathname.startsWith("/blog")) {
const response = NextResponse.next();
await new Promise((resolve) => {
setTimeout(resolve, 10);
});
return response;
}
}

};
6 changes: 4 additions & 2 deletions pages/_error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ const Error: NextPage<Props> = ({ statusCode }) => {
);
};

Error.getInitialProps = ({ res, err }: NextPageContext) => {
Error.getInitialProps = async ({ res, err }: NextPageContext) => {
if (typeof window == "undefined") {
const newrelic = require("newrelic");
// use dynamic import to avoid typescript error
// https://2ality.com/2017/01/import-operator.html
const newrelic = await import("newrelic");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to be working with the current setup.

It might be because there are some left overs from a nextjs custom server and babel configs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's not working?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all good, it was my mistake, put the comment for myself really to remember to check some things :)

newrelic.noticeError(err);
} else {
window.newrelic.noticeError(err);
Expand Down