Commit 92d4b73a authored by wty's avatar wty

修正静态资源加载

parent 6567d769
......@@ -45,27 +45,26 @@ const port = 3000
// dockerApp.startServer()
// })
app.engine('html', engines.mustache)
app.set('view engine', 'html')
app.use((req, res, next) => {
const url = req.url
const header = {
'Access-Control-Allow-Credentials': true,
'Access-Control-Allow-Origin': req.headers.origin || '*',
'Access-Control-Allow-Headers': 'X-Requested-With,Content-Type',
'Access-Control-Allow-Methods': 'PUT,POST,GET,DEconstE,OPTIONS',
'Content-Type': 'application/json; charset=utf-8'
}
if (url.includes('static')){
header["Content-Type"] = 'text/html; charset=utf-8'
}
//设置相应头
res.set(header)
req.method === 'OPTIONS' ? res.status(204).end() : next()
})
//
// app.use((req, res, next) => {
// const url = req.url
//
// const header = {
// 'Access-Control-Allow-Credentials': true,
// 'Access-Control-Allow-Origin': req.headers.origin || '*',
// 'Access-Control-Allow-Headers': 'X-Requested-With,Content-Type',
// 'Access-Control-Allow-Methods': 'PUT,POST,GET,DEconstE,OPTIONS',
// 'Content-Type': 'application/json; charset=utf-8'
// }
//
// if (url.includes('static')){
// header["Content-Type"] = 'text/html; charset=utf-8'
// }
// //设置相应头
// res.set(header)
// req.method === 'OPTIONS' ? res.status(204).end() : next()
// })
......@@ -75,9 +74,20 @@ app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({extended: false}));
app.use(cookieParser());
app.use('/static', express.static(path.join(__dirname, 'static')));
app.use('/', indexRouter);
app.engine('html', engines.mustache)
app.set('view engine', 'html')
app.set('views', path.join(__dirname, '/staticFile/build'));
// app.use(favicon(path.join(__dirname, "../static/build/favicon.ico")));
// app.use('/scripts', express.static(path.join(__dirname, 'node_modules')));
// app.use(express.static(path.join(__dirname, 'build')));
app.get('/', function(req, res){
res.type('html')
res.render('index.html');
});
app.use('/staticFile', express.static(path.join(__dirname, 'staticFile')));
app.use('/static',express.static(path.join(__dirname, 'staticFile/build/static')))
// app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/query', queryRouter)
app.use('/add', addRouter)
......
......@@ -18,6 +18,7 @@
"eureka-node": "^0.3.9",
"express": "~4.16.1",
"morgan": "~1.9.1",
"mustache": "^4.2.0",
"mysql": "^2.18.1",
"nodemon": "^2.0.12",
"pm2": "^5.1.2",
......
......@@ -3289,6 +3289,11 @@ ms@^2.1.1:
resolved "http://npm.dui88.com:80/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
integrity sha1-V0yBOM4dK1hh8LRFedut1gxmFbI=
mustache@^4.2.0:
version "4.2.0"
resolved "http://npm.dui88.com:80/mustache/-/mustache-4.2.0.tgz#e5892324d60a12ec9c2a73359edca52972bf6f64"
integrity sha1-5YkjJNYKEuycKnM1ntylKXK/b2Q=
mute-stream@~0.0.4:
version "0.0.8"
resolved "http://npm.dui88.com:80/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment