Skip to content

Commit 2dfb9bc

Browse files
author
Nicola Greco
committed
Merge pull request #106 from deiu/master
Handle CORS before everything else
2 parents 654b2a8 + a86ead7 commit 2dfb9bc

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

‎index.js‎

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,22 @@ function proxy (app, path) {
133133

134134
function routes () {
135135
var router = express.Router('/');
136+
137+
// Add Link headers
138+
router.use(header.linksHandler);
139+
140+
// Setting CORS
141+
router.use(cors({
142+
methods: [
143+
'OPTIONS', 'HEAD', 'GET',
144+
'PATCH', 'POST', 'PUT', 'DELETE'
145+
],
146+
exposedHeaders: 'User, Location, Link, Vary, Last-Modified, Content-Length',
147+
credentials: true,
148+
maxAge: 1728000,
149+
origin: true
150+
}));
151+
136152
router.use('/*', function(req, res, next) {
137153
getRawBody(req,
138154
{
@@ -161,25 +177,10 @@ function routes () {
161177

162178
// Convert json-ld and nquads to turtle
163179
router.use('/*', parse.parseHandler);
164-
165-
// Add links headers
166-
router.use(header.linksHandler);
167180

168181
// Add response time
169182
router.use(responseTime());
170183

171-
// Setting CORS
172-
router.use(cors({
173-
methods: [
174-
'OPTIONS', 'HEAD', 'GET',
175-
'PATCH', 'POST', 'PUT', 'DELETE'
176-
],
177-
exposedHeaders: 'User, Location, Link, Vary, Last-Modified, Content-Length',
178-
credentials: true,
179-
maxAge: 1728000,
180-
origin: true
181-
}));
182-
183184
// HTTP methods handlers
184185
router.get('/*', getHandler.handler);
185186
router.head('/*', getHandler.headHandler);

0 commit comments

Comments
 (0)