parent
e38474ce40
commit
03eae2f1ef
6 changed files with 17 additions and 5 deletions
11
server/routes/asset.routes.js
Normal file
11
server/routes/asset.routes.js
Normal 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;
|
|
@ -5,6 +5,5 @@ const router = new Router();
|
||||||
|
|
||||||
router.route('/projects/:project_id/files').post(FileController.createFile);
|
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/files/:file_id').delete(FileController.deleteFile);
|
||||||
router.route('/projects/:project_id/*?').get(FileController.getFileContent);
|
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|
|
@ -28,9 +28,6 @@ router.route('/:username/sketches/:project_id').get((req, res) => {
|
||||||
res.send(renderIndex());
|
res.send(renderIndex());
|
||||||
});
|
});
|
||||||
|
|
||||||
router.route('/:username/sketches/:project_id/*').get((req, res) => {
|
|
||||||
getProjectAsset(req, res);
|
|
||||||
});
|
|
||||||
|
|
||||||
// router.route('/full/:project_id').get((req, res) => {
|
// router.route('/full/:project_id').get((req, res) => {
|
||||||
// res.send(renderIndex());
|
// res.send(renderIndex());
|
||||||
|
|
|
@ -24,6 +24,7 @@ import files from './routes/file.routes';
|
||||||
import aws from './routes/aws.routes';
|
import aws from './routes/aws.routes';
|
||||||
import serverRoutes from './routes/server.routes';
|
import serverRoutes from './routes/server.routes';
|
||||||
import embedRoutes from './routes/embed.routes';
|
import embedRoutes from './routes/embed.routes';
|
||||||
|
import assetRoutes from './routes/asset.routes';
|
||||||
import { requestsOfTypeJSON } from './utils/requestsOfType';
|
import { requestsOfTypeJSON } from './utils/requestsOfType';
|
||||||
|
|
||||||
import { renderIndex } from './views/index';
|
import { renderIndex } from './views/index';
|
||||||
|
@ -91,6 +92,7 @@ app.use('/api', requestsOfTypeJSON(), sessions);
|
||||||
app.use('/api', requestsOfTypeJSON(), projects);
|
app.use('/api', requestsOfTypeJSON(), projects);
|
||||||
app.use('/api', requestsOfTypeJSON(), files);
|
app.use('/api', requestsOfTypeJSON(), files);
|
||||||
app.use('/api', requestsOfTypeJSON(), aws);
|
app.use('/api', requestsOfTypeJSON(), aws);
|
||||||
|
app.use(assetRoutes);
|
||||||
// this is supposed to be TEMPORARY -- until i figure out
|
// this is supposed to be TEMPORARY -- until i figure out
|
||||||
// isomorphic rendering
|
// isomorphic rendering
|
||||||
app.use('/', csrfToken, serverRoutes);
|
app.use('/', csrfToken, serverRoutes);
|
||||||
|
|
|
@ -26,7 +26,7 @@ function resolveLinksInString(content, files, projectId) {
|
||||||
while (resolvedFilePath.startsWith('/')) {
|
while (resolvedFilePath.startsWith('/')) {
|
||||||
resolvedFilePath = resolvedFilePath.substr(1);
|
resolvedFilePath = resolvedFilePath.substr(1);
|
||||||
}
|
}
|
||||||
newContent = newContent.replace(filePath, `/api/projects/${projectId}/${resolvedFilePath}`);
|
newContent = newContent.replace(filePath, `/sketches/${projectId}/assets/${resolvedFilePath}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,10 @@
|
||||||
header does not match `type`
|
header does not match `type`
|
||||||
*/
|
*/
|
||||||
const requestsOfType = type => (req, res, next) => {
|
const requestsOfType = type => (req, res, next) => {
|
||||||
|
console.log(req);
|
||||||
|
console.log(req.get('content-type'));
|
||||||
if (req.get('content-type') != null && !req.is(type)) {
|
if (req.get('content-type') != null && !req.is(type)) {
|
||||||
|
console.log('in requests of type error');
|
||||||
return next({ statusCode: 406 }); // 406 UNACCEPTABLE
|
return next({ statusCode: 406 }); // 406 UNACCEPTABLE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue