Browse Source

Allow control use cdn or not with header SYZOJ-No-CDN

master
Menci 6 years ago
parent
commit
cfbbf6b4bd
  1. 5
      app.js
  2. 2
      views/header.ejs
  3. 2
      views/util.ejs

5
app.js

@ -170,7 +170,8 @@ global.syzoj = {
app.use(Session(sessionConfig));
app.use((req, res, next) => {
// req.session.user_id = 1;
res.locals.useLocalLibs = !!req.headers['syzoj-no-cdn'];
let User = syzoj.model('user');
if (req.session.user_id) {
User.fromID(req.session.user_id).then((user) => {
@ -181,7 +182,7 @@ global.syzoj = {
res.locals.user = null;
req.session.user_id = null;
next();
})
});
} else {
if (req.cookies.login) {
let obj;

2
views/header.ejs

@ -12,7 +12,7 @@
<link href="<%- lib('KaTeX/0.10.0/katex.min.css') %>" rel="stylesheet">
<link href="<%- lib('morris.js/0.5.1/morris.css') %>" rel="stylesheet">
<link href="/style.css?20181212" rel="stylesheet">
<% if (!syzoj.config.google_fonts_url) { %>
<% if (useLocalLibs || !syzoj.config.google_fonts_url) { %>
<link href="<%- syzoj.utils.makeUrl(['google-fonts', 'fira-mono.css']) %>" rel="stylesheet">
<link href="<%- syzoj.utils.makeUrl(['google-fonts', 'lato.css']) %>" rel="stylesheet">
<link href="<%- syzoj.utils.makeUrl(['google-fonts', 'open-sans.css']) %>" rel="stylesheet">

2
views/util.ejs

@ -67,7 +67,7 @@ this.iconHidden = [
];
this.lib = uri => {
if (!syzoj.config.cdnjs_url) {
if (useLocalLibs || !syzoj.config.cdnjs_url) {
return syzoj.utils.makeUrl(['cdnjs', uri]);
} else {
return syzoj.config.cdnjs_url + '/' + uri;

Loading…
Cancel
Save