From cc3fbfc204b296efbce64a4c7163600c4624adf4 Mon Sep 17 00:00:00 2001 From: Ggoggo Date: Sun, 14 Jun 2015 11:03:07 +0900 Subject: [PATCH] static file response with regex --- server.js | 38 ++++++++------------------------------ 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/server.js b/server.js index 636906e..36f2960 100644 --- a/server.js +++ b/server.js @@ -6,53 +6,32 @@ app.get('/', function (req, res) { res.sendfile( __dirname + '/front/index.html'); }); -app.get('/form.css', function (req, res) { - res.sendfile( __dirname + '/front/form.css'); -}); - -app.get('/form.js', function (req, res) { - res.sendfile( __dirname + '/front/form.js'); -}); app.get('/intro', function (req, res) { res.sendfile( __dirname + '/front/intro.html'); }); -app.get('/intro.js', function (req, res) { - res.sendfile( __dirname + '/front/intro.js'); -}); - app.get('/notice', function (req, res){ res.sendfile( __dirname + '/front/notice.html'); }); -app.get('/notice.css', function (req, res){ - res.sendfile( __dirname + '/front/notice.css'); -}); - -app.get('/notice.js', function (req, res){ - res.sendfile( __dirname + '/front/notice.js'); -}); - -app.get('/jquery', function (req, res){ - res.sendfile( __dirname + '/front/jquery-1.11.1.js'); +app.get(/\/.*.css/, function(req, res){ + res.sendFile(__dirname + "/front"+req.path); }); - -app.get('/res/logo.png', function (req, res){ - res.sendfile( __dirname + '/front/res/logo.png'); +app.get(/\/.*.js/, function(req, res){ + res.sendFile(__dirname + "/front"+req.path); }); -app.get('/res/login.png', function (req, res){ - res.sendfile( __dirname + '/front/res/login.png'); +app.get(/\/.*.png/, function(req, res){ + res.sendFile(__dirname + "/front"+req.path); }); -app.get('/res/banner.png', function (req, res){ - res.sendfile( __dirname + '/front/res/banner.png'); +app.get('/jquery', function (req, res){ + res.sendfile( __dirname + '/front/jquery-1.11.1.js'); }); - var server = app.listen(process.env.PORT||3000, function () { var host = server.address().address; @@ -61,4 +40,3 @@ var server = app.listen(process.env.PORT||3000, function () { console.log('Example app listening at http://%s:%s', host, port); }); -