fixes #479 and fixes #449

This commit is contained in:
Cassie Tarakajian 2017-11-28 14:48:50 -05:00
parent e38474ce40
commit 03eae2f1ef
6 changed files with 17 additions and 5 deletions

View file

@ -0,0 +1,11 @@
import { Router } from 'express';
import { getProjectAsset } from '../controllers/project.controller';
import { getFileContent } from '../controllers/file.controller';
const router = new Router();
router.route('/:username/sketches/:project_id/*').get(getProjectAsset);
router.route('/sketches/:project_id/assets/*?').get(getFileContent);
export default router;

View file

@ -5,6 +5,5 @@ const router = new Router();
router.route('/projects/:project_id/files').post(FileController.createFile);
router.route('/projects/:project_id/files/:file_id').delete(FileController.deleteFile);
router.route('/projects/:project_id/*?').get(FileController.getFileContent);
export default router;

View file

@ -28,9 +28,6 @@ router.route('/:username/sketches/:project_id').get((req, res) => {
res.send(renderIndex());
});
router.route('/:username/sketches/:project_id/*').get((req, res) => {
getProjectAsset(req, res);
});
// router.route('/full/:project_id').get((req, res) => {
// res.send(renderIndex());

View file

@ -24,6 +24,7 @@ import files from './routes/file.routes';
import aws from './routes/aws.routes';
import serverRoutes from './routes/server.routes';
import embedRoutes from './routes/embed.routes';
import assetRoutes from './routes/asset.routes';
import { requestsOfTypeJSON } from './utils/requestsOfType';
import { renderIndex } from './views/index';
@ -91,6 +92,7 @@ app.use('/api', requestsOfTypeJSON(), sessions);
app.use('/api', requestsOfTypeJSON(), projects);
app.use('/api', requestsOfTypeJSON(), files);
app.use('/api', requestsOfTypeJSON(), aws);
app.use(assetRoutes);
// this is supposed to be TEMPORARY -- until i figure out
// isomorphic rendering
app.use('/', csrfToken, serverRoutes);

View file

@ -26,7 +26,7 @@ function resolveLinksInString(content, files, projectId) {
while (resolvedFilePath.startsWith('/')) {
resolvedFilePath = resolvedFilePath.substr(1);
}
newContent = newContent.replace(filePath, `/api/projects/${projectId}/${resolvedFilePath}`);
newContent = newContent.replace(filePath, `/sketches/${projectId}/assets/${resolvedFilePath}`);
}
}
}

View file

@ -4,7 +4,10 @@
header does not match `type`
*/
const requestsOfType = type => (req, res, next) => {
console.log(req);
console.log(req.get('content-type'));
if (req.get('content-type') != null && !req.is(type)) {
console.log('in requests of type error');
return next({ statusCode: 406 }); // 406 UNACCEPTABLE
}