Skip to content

Instantly share code, notes, and snippets.

@avaforvr
Last active May 16, 2020 10:06
Show Gist options
  • Save avaforvr/472c3ad2fce7aa94aa482d279ca85368 to your computer and use it in GitHub Desktop.
Save avaforvr/472c3ad2fce7aa94aa482d279ca85368 to your computer and use it in GitHub Desktop.
// 方案一: cookie-parser 中间件
// server.js
const cookieParser = require('cookie-parser');
const server = express();
server.use(cookieParser());
// 方案二:next-cookies
// pages/_app.js
import nextCookies from 'next-cookies';
MyApp.getInitialProps = async (appContext) => {
const cookies = nextCookies(appContext.ctx);
};
function filterLang(url) {
let filtered = url;
if (url.search(/^\/[a-z][a-z]\//) === 0) {
filtered = url.slice(3);// 以 /[lang]/ 开头的路径
} else if (url.length === 3) {
filtered = '/';// /[lang]
}
return filtered;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment